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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -