1

There is some part of code.

application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/gbook', Guestbook)
])

As I understand it is a list of tuples:

[('/', MainPage), ('/gbook', Guestbook)]

Correct me please if I'm wrong.

And I have question: Where is obvious creation of instance of MainPage class and Guestbook?

Something like that: x = MainPage('/')

If this happens by this tuple ('/', MainPage), then my question: how it's happens?

I need some explanation.

1
  • Yes, that is a list of tuples. "Where is obvious creation of instance..." - nowhere in the code you're showing. Explanation of code is off-topic here, particularly if you don't even show the code in question. Commented Oct 21, 2014 at 14:14

2 Answers 2

3

The WSGIApplication it self creates the instances of the classes. In python you can pass classes around, just like you would pass instances of a class. For example:

class A:
    def __init__(self):
        print "A Created"

def foo(cls):
    inst = cls()

foo(A)

If you run this script it will print out "A Created" because you are passing in the class to foo which is creating a new instance from that class.

Sign up to request clarification or add additional context in comments.

4 Comments

Small another question: is there some way to get access to variables of class A?
Yes, it's just like everything else in python.
but in this case I have no any name of instance of class. How it is possible without global var?
There is a difference between a class and an instance. In the example of inst is an Object that is an instance of A. If A had static variables or functions than inside foo you could access them with cls.staticFunction().
0

You can check source code of webapp2 to verify this.

In __init__ function of WSGIApplication , list '[('/', MainPage),('/gbook', Guestbook)]' will be passed as variable routes, then they will be instantiated by Route class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.