0

Having a strange error here. I had a previous directory structured as follows

main.py
foldername
     modulename.py

now in main.py I called modulename.py by using import modulename.py as mn

now I am making changes but I still want to use the modules as before, so in a completely different location on my computer I have set up the structure as before:

newmain.py
foldername
     modulename.py

to make sure I am working in the right directory I used:

import os
os.chdir('NewMainPath/')

which correctly sets the directory of the file but if I now use

import modulename.py as mn

it for some reason is linking to the previous modulename.py That means if I make any changes it won't pick them up and is just linking to the previous location and I can't figure out why.

user33484
  • 740
  • 2
  • 9
  • 36

1 Answers1

0

Instead of using os.chdir(newpath)

Try using

import sys
sys.path.insert(0, '/newpath')

import file

Also worth reading: Importing files from different folder in Python

Community
  • 1
  • 1
cyberbemon
  • 3,000
  • 11
  • 37
  • 62