On Fri, Nov 7, 2008 at 4:16 PM, Duncan Booth <[EMAIL PROTECTED]> wrote: > There is a really big advantage to being explicit in this situation: you no > longer have to make sure that all your constructors use a unique set of > types. Consider: > > class Location(object): > def __init__(self, lat, long): ... > > @classmethod > def from_city(name): ... > > @classmethod > def from_postcode(name): ... > > 'from_string' is a bad name here for your factory method: you should try to > make it clear what sort of string is expected.
Yes, that's what I was going to do. But, for example, I have a parse method to create such object from a string. So I need to call this method to actually create the object. Now I must put the code of the parse method into the @classmethod constructor. What if I need the parse method to be called in other parts of the program? -- http://mail.python.org/mailman/listinfo/python-list