473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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
2 1318
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Average_Joe | last post by:
Hello PHP people, Was wondering if PHP5 had some sort of "nested class" functionality. I'm trying to figure out how to return an object (with a private constructor) that has access to...
5
by: devu | last post by:
Currently I'm working on a class that performs a batch process as per scheduling for all employees in a company. Being a batch process load is obviously a huge factor. The process first needs to...
7
by: Wolfgang Jeltsch | last post by:
Hello, I want to write a list class with an iterator class as an inner class. The iterator class must have access to certain private members of the list class in order to do its job. Here is a...
11
by: Sumit Nagpal | last post by:
Hi All, My application reads a 'Class' name (as a string) from a file at Run time. Can i create an instance this Class ? Thanks Sumit
9
by: MariusI | last post by:
Consider the following class layout public class Order { public ProductOrder AddProductOrder(/* variables required to create a product order */) { /* Check if the product order can be added...
6
by: Philip Potter | last post by:
I have a graph data structure. It goes something like this: class GraphNode { private: friend class Graph; // successor GraphNodes stored as indices of the Graph's array int value; int next1,...
4
by: Pyenos | last post by:
class Model: Controller() class View: Model() class Controller:pass Python interpreter complains that 'Name Error: Controller()' not defined.
5
by: Pyenos | last post by:
class One: Two() #can't instantiate class Two: Three() #can't instantiate class Three:pass
9
by: Matthias Buelow | last post by:
Hi folks, I've got something like: class Outer { int f(); friend class Inner; class Inner { int g() {
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.