How do I get the path and name of the file that is currently executing?

后端 未结 29 2368
你的背包
你的背包 2020-11-22 06:43

I have scripts calling other script files but I need to get the filepath of the file that is currently running within the process.

For example, let\'s say I have th

29条回答
  •  既然无缘
    2020-11-22 07:14

    import os
    os.path.dirname(os.path.abspath(__file__))
    

    No need for inspect or any other library.

    This worked for me when I had to import a script (from a different directory then the executed script), that used a configuration file residing in the same folder as the imported script.

提交回复
热议问题