0

I'm currently using the code below to find a configuration file in the current project

kRootPath       = os.path.dirname(os.path.abspath(__file__))
kConfRootPath   = os.path.join(kRootPath, '..', 'ConfigFiles' )

This currently works for my original project. I now have multiple projects that want to use this include file. I need the location of the file that called the include instead of the include itself.

Details:

Project 1
  Config
    1a.cfg
    1b.cfg
  Code
    code1a.py
    code1b.py
    theInclude.py
Project 2
  Config
    2a.cfg
    2b.cfg
  Code
    code2a.py
    code2b.py

If all code files include theInclude.py then the include file should return the configure Path for:

  • project 1 if included from code1a.py or code1b.py
  • project 2 if included from code2a.py or code2b.py
Keith
  • 4,129
  • 3
  • 13
  • 25
  • maybe look into inspect module? [`Get __name__ of calling function's module in Python`](https://stackoverflow.com/questions/1095543/get-name-of-calling-functions-module-in-python) – chickity china chinese chicken Oct 20 '21 at 22:58
  • That seams to be the name of the calling function. Not the file path of the calling file. Also this code is OUT in the open. Not inside a function so there is no calling function. The file is simply being included and the path information is collected. – Keith Oct 20 '21 at 23:14

0 Answers0