Python: How to import from an __init__.py file? Python: How to import from an __init__.py file? flask flask

Python: How to import from an __init__.py file?


The init.py files are automatically imported when you import the package they are in. For example, say the init.py is in a package called foo. When you import foo

import foofrom foo import *import foo as ...

the init file gets called. And are you using python 2 or 3? If you are using python 3, you will need to use dynamic imports:

from * import __init__

In general, it is a bad practice to import from init, I would suggest trying to place this code in another file in the package.