can't instantiate following inner class

Larry Bates larry.bates at websafe.com
Wed Dec 27 19:41:18 EST 2006


Pyenos wrote:
> class One:
>         Two() #can't instantiate
> class Two:
>         Three() #can't instantiate
> class Three:pass
> 
> 
> 
You keep posting examples with the same problems
that others have addressed.  It appears you are trying
to write Python in a way that some "other" language
works.  You really should see the posted solutions and
go through the tutorial before posting again.

Note the following is "normally" not used Python:
    Two()


This would instantiate a Two class that wouldn't be bound
to anything so you could never access it again in the
future.  It would then be thrown away by garbage collection.
Proper way is:

class One:
    def __init__(self):
        self.Two=Two()

Of course Two must be a proper class definition also.

class Two:
    def __init__(self):
        self.Three=Three()

class Three:
    pass

-Larry



More information about the Python-list mailing list