Feb-13-2023, 02:14 PM
I'm new to python and am trying to migrate my flask app to a package structure.
I have run.py sitting in a directory alongside a /myproject directory.:
/myproject contains the modules along with an __init__.py, which imports routes.py:
I have run.py sitting in a directory alongside a /myproject directory.:
from myproject import app if __name__ == '__main__': app.run()When I run python run.py, the debugger confirms that the import runs first on line 1 from myproject import app (as I would expect), and then again when app.run() is executed (as I would not expect). This is a problem because one of the imported modules declares a global object that is only allowed to be instantiated once..
/myproject contains the modules along with an __init__.py, which imports routes.py:
from flask import Flask app = Flask(__name__) from myproject import routesI apologize if this should be obvious, but why is the import happening twice, and can it be prevented?