[Tutor] Re-instantiate within __init__
by Jan Eden other posts by this author
Apr 19 2006 7:40AM messages near this date
[Tutor] Fw: anybody tried Google calendar?
|
Re: [Tutor] Re-instantiate within __init__
Hi,
is it correct that an object cannot be re-instantiated within it's __init__ method?
I tried:
class Omega:
def Display(self):
print self
class Alpha(Omega):
def __init__(self):
self = Beta()
class Beta(Omega):
def __init__(self):
pass
objectus = Alpha()
objectus.Display()
which prints
<__main__.Alpha instance at 0x54d50>
Background: I need to create a new object upon instantiation when a database query returns n
o records. The rest of the program should just use the new object.
Is there any way to achieve this? I can always place the equivalent of 'self = Beta()' in th
e Display() function:
def Display(self):
if self.not_found:
self = Beta()
self.Display()
return
print self
but this does not look very elegant.
Thanks,
Jan
--
Any sufficiently advanced technology is insufficiently documented.
_______________________________________________
Tutor maillist - Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Jan Eden
Danny Yoo
Kent Johnson
Alan Gauld
|