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

failing to instantiate an inner class because of order of inner classes

P: n/a
class model:pass
class view:
model()
class controller:
model()

I can instantiate clsss model from inside class view but I can't
instantiate class model from inside controller, due to the nature of
python interpreter.

I wish to circumvent this restriction by:

class model:pass
class view:
parent_class.model()
class controller:
parent_class.model()

but, I don't know the built-in variable that points to the parent
class. Could someone tell me how can I instantiate class model from
inside controller AND instantiate class model from inside view?
Dec 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Pyenos wrote:
class model:pass
class view:
model()
class controller:
model()

I can instantiate clsss model from inside class view but I can't
instantiate class model from inside controller, due to the nature of
python interpreter.

I wish to circumvent this restriction by:

class model:pass
class view:
parent_class.model()
class controller:
parent_class.model()

but, I don't know the built-in variable that points to the parent
class. Could someone tell me how can I instantiate class model from
inside controller AND instantiate class model from inside view?
I would try the following:

class model:
def printFoo(self):
print "foo"
class view:
def __init__(self):
self.model = model()
class controller:
def __init__(self):
self.model = model()

Then you can do:
vObj = view()
vObj.model.printFoo()

And:
cObj = controller()
cObj.model.printFoo()

Dec 27 '06 #2

P: n/a
"Edward Kozlowski" <ek*********@gmail.comwrites:
Pyenos wrote:
class model:pass
class view:
model()
class controller:
model()

I can instantiate clsss model from inside class view but I can't
instantiate class model from inside controller, due to the nature of
python interpreter.

I wish to circumvent this restriction by:

class model:pass
class view:
parent_class.model()
class controller:
parent_class.model()

but, I don't know the built-in variable that points to the parent
class. Could someone tell me how can I instantiate class model from
inside controller AND instantiate class model from inside view?

I would try the following:

class model:
def printFoo(self):
print "foo"
class view:
def __init__(self):
self.model = model()
class controller:
def __init__(self):
self.model = model()

Then you can do:
vObj = view()
vObj.model.printFoo()

And:
cObj = controller()
cObj.model.printFoo()
I've made an error in the original article that you have quoted here
but I have cancelled it. However, I have understood your solution and
I think it is helpful. Thank you.
Dec 27 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.