failing to instantiate an inner class because of its order

Pyenos pyenos at pyenos.org
Wed Dec 27 18:37:12 EST 2006


Pyenos <pyenos at pyenos.org> writes:

> Pyenos <pyenos at pyenos.org> writes:
> 
> > class Model:
> >         Controller() #problem
> > 
> > class View:
> >         Model()
> > 
> > class Controller:pass
> > 
> > 
> > Python interpreter complains that 'Name Error: Controller()' not defined.
> >         
> 
> Following Edward Kozlowski's advice I can suggest to myself a solution:
> 
> class Model:pass
> 
> class View:
>         Model() #this part is fine
> 
> class Controller:
>         def __init__(self):
>                 self.Model=Model()
> 
> Controller.Model.Controller() #solution

class Model:
    def fuck(self):print "fuck!"

class View:
        Model() #this part is fine

class Controller:
        def __init__(self):
                self.Model=Model()
        
Controller().Model.fuck() #actually slight problem in previous solution


Has to call in this way. I have confirmed this works.




More information about the Python-list mailing list