return same type of object
Steve Holden
steve at holdenweb.com
Tue Oct 24 11:52:39 EDT 2006
David Isaac wrote:
> Instances of MyClass have a method that
> returns another instance. Ignoring the details
> of why I might wish to do this, I could
> return MyClass()
> or
> return self.__class__()
>
> I like that latter better. Should I?
> Should I do something else altogether?
>
The latter solution is more Pythonic, IMHO, as it works for subclasses.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list