1

I have python module, that i added to some other source root folder like this

MyProject/my_new_file.py
MyProject/MyModule/__init__.py
MyProject/MyModule/script1.py
MyProject/MyModule/script2.py

And because root source is folder "MyProject", script1.py cannot include script2.py file like this:

from script2 import my_awesome_function

Does someone know a way that my modules imports are isolated within their own folder, so i dont have to reference import path from source root

martineau
  • 119,623
  • 25
  • 170
  • 301
Jernej Habjan
  • 148
  • 1
  • 14
  • 1
    See [Relative imports for the billionth time](https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time). – martineau Oct 01 '18 at 17:34

1 Answers1

0

You can use relative imports:

from .script2 import my_awesome_function
blhsing
  • 91,368
  • 6
  • 71
  • 106
  • Yes, but is there any way that i could set sys.path() in __init__.py so i wouldnt have to set these relative imports everywhere – Jernej Habjan Oct 01 '18 at 16:54
  • @JernejHabjan: `sys.path` is a modifiable list, so you can add, change, and delete items from/in it if you wish. – martineau Oct 01 '18 at 17:32