0

I have a a project with following path:

shift/
     Code/
          __init__.py
          mymain.py
          run.py
     Test/
         __init__.py
         tester.py
         runtester.py

     requirments.txt

in mymain.py there is a class which I need to import from the tester.py. So in tester.py I'm importing class as following codes but none of them work.

from Code.mymain import NewClass
from .mymain import NewClass
from mymain import NewClass
from shift.Code.mymain import NewClass

I also tried to insert the path in tester.py:

cwd = os.getcwd()
sys.path.insert(0, cwd)

However still confused why it does not know my file

1 Answers1

0

Try like this

import sys
import os
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + '\\Code') 
from mymain import NewClass

More details at : importing files from different folder

PyDeveloper
  • 106
  • 9