By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,965 Members | 1,962 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,965 IT Pros & Developers. It's quick & easy.

failing to instantiate an inner class because of its order

P: n/a
class Model:
Controller()

class View:
Model()

class Controller:pass
Python interpreter complains that 'Name Error: Controller()' not defined.

Dec 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Pyenos <py****@pyenos.orgwrites:
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
Dec 27 '06 #2

P: n/a
Pyenos <py****@pyenos.orgwrites:
Pyenos <py****@pyenos.orgwrites:
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.

Dec 27 '06 #3

P: n/a
At Wednesday 27/12/2006 20:37, Pyenos wrote:
>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.
The Model() inside View is *not* fine - you construct a Model
instance just to discard it! Besides some side effects that
constructing a Model() might have, this is useless.
If you are trying to implement a real MVC, usually the model exists
by itself even before you need the view, so usually the view
constructor gets the model as an argument.
I prefer to use lowercase attribute names: self.model = Model(), this
way there is no confusion between model (an instance) and Model (a class).
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 28 '06 #4

P: n/a
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.
What is even the point of the class View there since you don't use it?

/buffi (buffis.com)

Dec 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.