[Pythonmac-SIG] self-instantiating instances in pyhton
has
hengist.podd at virgin.net
Thu Jan 13 00:49:00 CET 2005
Rayme Jernigan wrote:
>I'm looking for a language to abuse for a project I'm working on. I
>know a little Python, but I do not know if it can do this: I'd like to
>define some class "N" that instantiates objects that can instantiate
>fresh new objects of that same class... without external controller
>code.
This the sort of thing you mean?
class _Base:
def __call__(self, *args, **kargs):
return self.__class__(*args, **kargs)
class Foo(_Base):
pass
class Bar(_Base):
pass
f = Foo()
b = Bar()
print f, f()
print b, b()
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
More information about the Pythonmac-SIG
mailing list