1

I have the following problem and would like to ask you what is the best way to solve it.

I the following structure of files:

  1. Main Folder 1.1 Subfolder1 1.1.1 SubSubfolder1

I have main python script in main folder, and other sripts in subfolders, which are importing some other scripts from subsubfloders. I need to run the main script in Main Folder, which is importing scripts from subfolders. Each subfolder is standalone, and I just need to import and run scripts available in subfolders (which themselves are importing some other scripts).

I am getting an error because when I import scripts, the running directory is not changing automatically when the script is called.

So I need that if the script is imported, the dependent scripts were imported from the relative path.

Thanks

NairB
  • 9
  • 3
  • As you didn't provide any script you're using we cannot guess why it's not working and what is the error you're getting. Try to read about absolute and relative import here: https://realpython.com/absolute-vs-relative-python-imports/ – Carl HR Jun 26 '22 at 16:55

1 Answers1

0

I believe using sys.path.append method from sys built-in module should work.
Here is the syntax :

sys.path.append(YourPath)
import YourScript

please note that your path should not lead to a file, but to a folder

Pauel3312
  • 34
  • 4