Relative import in Python 3 not working -
i have following directory:
mydirectory ├── __init__.py ├── file1.py └── file2.py
i have function f defined in file1.py.
if, in file2.py, do
from .file1 import f
i following error:
systemerror: parent module '' not loaded, cannot perform relative import
why? , how make work?
since file1
, file2
in same directory, don't need have __init__.py
file. if you're going scaling up, leave there.
to import in file in same directory, this
from file1 import f
i.e., don't need relative path .file1
because in same directory.
if main function, script, or whatever, running whole application in directory, have make relative wherever being executed.
Comments
Post a Comment