Nicola Musatti wrote: > > def factory(info): > > k = Klass() > > data = get_initial_data(info) > > k.set_data(data) > > return k > > > > to: > > > > def factory(info): > > data = get_initial_data(info) > > return Klass(data) > > > > What would be the value of doing the initialization in a separate > > method, rather than the constructor? > > I didn't express my intent clearly. I agree that in general your second > example is to be preferred to the first one. In fact the only reason I > could think of using the first scheme is when the second would lead to > Klass's __init__ method having a large number of parameters. > > What is important to me is to keep your get_initial_data() function > outside Klass if it's task is non trivial, e.g. it has to interact with > the OS or a DB.
why ? </F> -- http://mail.python.org/mailman/listinfo/python-list