How does these Python imports work? -


i'm started learning backend web development using python tutorial [here][1].

the first project simple hello world respond requests website home page.

whole program above project consist of 3 files:

mywebsite/     app/         __init__.py         views.py     run.py 

and python files below :

__init__.py

from flask import flask app = flask (__name__) app import views 

views.py

from app import app @app.route ('/') def sayhello():     return "hello world" 

run.py

from app import app app.run (debug = true) 

my origin question:

the program execute interpreting run.py. far know in first line of file, from app import app, search __init__.py object named app , if found, make available next lines, right? well, seems ok me (i think!).

the question is, why need from app import app in views.py while don't want execute it! mean want use file in __init__.py file, think enough import in __init__.py , don't need from app import app in views.py. wrong?


as side question :

when write from x import y, x , y?

  • is x directory or file?
  • is y file or object in file named __init__.py?

when write import z, z? file or object inside 1 of libraries?


i know question seems simple experts, migrate c python, , @ import #include in c , think origin of problem. read q&a in related issue, confused yet.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -