0

Here is the structure of my directory:

MyFolder
   -run.py
SecondFolder
   -class.py

What I have attempted is adding the directory path to sys.path within the run.py file and this will work only occasionally (not sure why):

import sys
sys.path.insert(0, '/Users/.../SecondFolder/class.py')
from class import Connection

How can I ensure the module is always loaded? Any help is greatly appreciated.

a.powell
  • 1,572
  • 4
  • 28
  • 39
  • 1
    Possible duplicate of [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – m_____z Aug 27 '19 at 14:00

1 Answers1

1

If SecondFolder doesn't have to be in the same location as MyFolder, you can add it to the python site-packages.

From there, you can import it as so:

from SecondFolder.class import Connection