I have following folder structure:
root
folder1
file1.py
file2.py
folder2
file3.py
How would the import of file1.py look like, if I want to import it in file3.py?
I tried different variants: from folder1.file1 import *, from .folder1.file1 import *, from folder1 import file1, and similar variations, unfortunately without success. Do I need to create an __init__.py file somewhere?
yes
__init__.pyshould be present inroot,folder1andfolder2The
__init__.pyfiles are required to make Python treat the directories as containing packages, they just be an empty filethen you can do
if a package’s
__init__.pycode defines a list named__all__, it is taken to be the list of module names that should be imported whenfrom package import *is encountered