I have recently been using web.py for some simple web applications in Python. I thought I understood how import statements, packages and modules worked but now I am a little confused.
According to web.py's API it says that the class application is located inside the module web.application. In order to use this class, the tutorial gives examples such as
import web
app = web.application(urls, globals())
What confuses me is how I am creating an instance of the application class using web.application. If there exists a class application that is inside a module named application within the web package, from what I have learned I would expect to have to do something as such :
web.application.application(urls, globals())
package -> module -> class
Could someone please clear up my confusion? Here is a link to the web.py API I am referencing http://webpy.org/docs/0.3/api#web.application
Thanks in advance for the help!
The attributes of application.py module have been imported into the __init__.py of the web package (via __all__).
In the __init__.py of the web package, you have:
from application import * # referring to application.py
And in application.py:
__all__ = [
    "application", "auto_application",
    "subdir_application", "subdomain_application", 
    "loadhook", "unloadhook",
    "autodelegate"
]
Therefore, the attributes specified in the __all__ found in application.py are now accessible directly from the top level import -- web.
You can read more about packages, __init__.py and __all__ 
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With