relative reference in python

Viewed 29

am beginner in python and working on multi folder structure and struggling to refer the files using relative path. tried in different ways to refer the files in other folders but ended up in error "attempted relative import with no known parent package". Can somebody explain how the relative paths will work in python?

here is the example what am trying to achieve.. folder structure Main source Function1 inputs 1.py 2.py uts test_1.py code_1.py code_2.py

Now inside test_1.py am trying to refer code_1 using relative path like

from ..code_1 import Code
from .code_1 import Code

but, ended up in error..

some where I found that we need to have init.py in each folder to use relative path and I created empty init.py in each folder but, no use..

I may get the answer but more importantly need to know how this relative path works in python.

Thanks in advance

0 Answers
Related