circular import python 1

circular import python

# File: flask.py
import flask

# This results in an error, as the file tries to import itself.
# The simplest solution is just to rename your file
# so that it has a name different from all your modules.

Here is what the above code is Doing:
1. The import statement is executed.
2. The interpreter defines the flask module.
3. The interpreter tries to find a flask.py file.
4. The interpreter finds the current file and tries to import it.
5. The interpreter sees that flask is being defined in this file and gets confused.

Similar Posts