ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-tutor
python-tutor
[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

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved