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

后端 未结 29 2762
你的背包
你的背包 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 06:52

    The __file__ attribute works for both the file containing the main execution code as well as imported modules.

    See https://web.archive.org/web/20090918095828/http://pyref.infogami.com/__file__

提交回复
热议问题