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

Discussion in 'Python' started by Pyenos, Dec 27, 2006.

  1. Pyenos

    Pyenos Guest

    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?
     
    Pyenos, Dec 27, 2006
    #1
    1. Advertising

  2. 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()
     
    Edward Kozlowski, Dec 27, 2006
    #2
    1. Advertising

  3. Pyenos

    Pyenos Guest

    "Edward Kozlowski" <> writes:

    > 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.
     
    Pyenos, Dec 27, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. E11
    Replies:
    1
    Views:
    4,937
    Thomas Weidenfeller
    Oct 12, 2005
  2. Carlo v. Dango
    Replies:
    14
    Views:
    1,103
    Alex Martelli
    Oct 19, 2003
  3. Adam Sandler

    LoadXml failing because field too long????

    Adam Sandler, Feb 5, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    741
    Martin Honnen
    Feb 6, 2007
  4. Pyenos
    Replies:
    4
    Views:
    240
    buffi
    Dec 28, 2006
  5. Pyenos
    Replies:
    5
    Views:
    359
    Gian Mario Tagliaretti
    Dec 28, 2006
Loading...

Share This Page