0

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

1
  • 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: realpython.com/absolute-vs-relative-python-imports Commented Jun 26, 2022 at 16:55

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.