can't instantiate following inner class

buffi bjorn.kempen at gmail.com
Wed Dec 27 20:41:16 EST 2006


Pyenos wrote:
> class One:
>         Two() #can't instantiate
> class Two:
>         Three() #can't instantiate
> class Three:pass

Python parses code from top to bottom.
Since it first tries to read the class One and finds the class Two
inside it, it throws an error since it is not defined yet.

Reverse the order and it will work (like this:)

class Three:pass
class Two:
        Three()
class One:
        Two()

Of course this makes no sense whatsoever as the poster above me wrote.
The reason that you can use classes in the order the second poster
wrote is because of init not being called until you make an instance of
that class, and by then all classes are loaded.

/buffi (buffis.com)




More information about the Python-list mailing list