Message6472
Logged In: YES
user_id=89016
> You're asking for the impossible though.
> I don't think any other OO language supports
> this automatically (although I
> could be wrong).
Python uses it, e.g. in Lib/UserString.py:
def rstrip(self): return self.__class__(self.data.rstrip
())
So if someone derives a new class X from UserString,
calling X("y ").rstrip() returns an X object. The only
assumption that UserString makes, is that the derived class
has a constructor that can handle at least the same
arguments as UserString.__init__.
This "virtual constructor" is used in several places:
grep -l "self.__class__(" `find -name '*.py' | grep -v Mac`
returns:
./dist/src/Lib/UserString.py
./dist/src/Lib/copy.py
./dist/src/Lib/MimeWriter.py
./dist/src/Lib/test/test_descr.py
./dist/src/Lib/xml/sax/xmlreader.py
./dist/src/Lib/UserList.py
./dist/src/Demo/pdist/rcvs.py
|
|
Date |
User |
Action |
Args |
2007-08-23 13:56:19 | admin | link | issue460020 messages |
2007-08-23 13:56:19 | admin | create | |
|