1

I'm doing Python for some time now, but this is the first time I stage it in a project with different script that refer to each other. The structure of the files is like this (simplified):

Project Folder
   |
   |__folder1
         |
         |__Folder1a
               |
               |__script1
         |
         |
         |__folder 1b
               |
               |__script2 
               |
               |__script3

So, because script2 and script3 both use functions in script 1, I'm now doing something like this, in both script2 and script3:

main_dir = os.path.dirname(os.path.realpath(__file__))
modules_dir = os.path.realpath(os.path.join(main_dir, '..', '..'))
sys.path.insert(0, modules_dir)

from folder1.folder1a.script1 import function1

The thing is: This way I need to put this code in every script, which is not very handy. I do have a settings script, so maybe I can put the referal code there. I'm just not sure how to do it in a way that is the most neat and efficient. Could someone help me with this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
user2133561
  • 155
  • 1
  • 10

0 Answers0