failing to instantiate an inner class because of its order

P

Pyenos

class Model:
Controller()

class View:
Model()

class Controller:pass


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

Pyenos

Pyenos said:
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
 
P

Pyenos

Pyenos said:
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 ****(self):print "****!"

class View:
Model() #this part is fine

class Controller:
def __init__(self):
self.Model=Model()

Controller().Model.****() #actually slight problem in previous solution


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

Gabriel Genellina

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

class View:
Model() #this part is fine

class Controller:
def __init__(self):
self.Model=Model()

Controller().Model.****() #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
 
B

buffi

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

class View:
Model() #this part is fine

class Controller:
def __init__(self):
self.Model=Model()

Controller().Model.****() #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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top