So, I want to input previously created classes in my current Python project.
For this purpose I created a folder called lib
and I create one __init__.py
file in it.
My file structure looks like this
project_folder
lib
class1_folder
class1.py
class2_folder
class2.py
_init_.py
project_script.py
In the __init__.py
file located in the main project folder, I have 2 lines of code.
from class1_folder import class1
from class2_folder import class2
I want to be able to use the classes that I implemented in my project_script.py
. How would I be able to call them if they are nested so deeply?
In project_script, I do the following from lib.class1_folder.class1 import *
But I get an ImportError: No module named class1_folder
You need to add the __init__.py
file to each folder which should be treated as a package (for your example, they should be added to class1_folder
and class2_folder
).