Importing modules in python3 can be unnecessarily confusing, especially when using virtualenv
Suppose you have this file structure:
.env
test.py
cool_modules
|--__init__.py
|--cool_module1.py
|--cool_module2.py
To prevent import errors while using virtualenv .env
:
cool_module1.py:
class CoolModule1():
...
cool_module2.py:
class CoolModule2():
...
Here's the critical part.
init.py:
# The part to note here is you have to use `parent_folder.child_file`
from cool_modules.cool_module1 import CoolModule1
from cool_modules.cool_module2 import CoolModule2
test.py:
from cool_modules import CoolModule1, CoolModule2
That's it!
If this helped you out, follow me on Twitter: emmanuel_n_k
Top comments (0)