creating a similar object from an derived class
smbaker at gmail.com
Wed Sep 3 21:09:03 CEST 2008
Let's say I have an object:
x = self.create_another()
... do something with X
Now I create a inherited class of this object:
If I call bar.create_another(), it will return a foo() instead of a
bar(). This isn't what I want. I would like bar.create_another() to
create an instance for bar(). Obviously I can do this by overriding
However, is there a way for me to modify foo() so that it
automatically creates objects of the derived class, so that I don't
have to continue to redefine create_another() ?
For example, I tried the following:
but it did not work.
More information about the Python-list