Ordani Sanchez
Ordani Sanchez

Reputation: 401

Change working directory of a imported module

i am having trouble with some modules i want to import, so let's me put a sample to explain better.

proyect/
  helpers/
    config.py
  locations/
    loc1.py
  pages/
    page1.py
  Tools/
    myTool.py

So whats happening is that in myTool.py i'm importing page1.py that import from loc1.py. to do that i'm appendind '../ ' to sys.path. The problem is that in loc1 is imported config.py and initialize, when it do that it working dir is TOols/ but i need it to be my proyect dir.

Upvotes: 0

Views: 1402

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599610

Modules don't have working dirs, only the program as a whole does.

You should add the proyect dir to sys.path at the start of the script, then import loc1 from locations.

Upvotes: 1

Related Questions