英文:
Python - Get Path of File from inside of Module
问题
I tried get Parent of Module and some os.path methods but None returned needed data.
我尝试获取模块的父目录和一些os.path方法,但都没有返回所需的数据。
英文:
so after some time searching i was unable to find how to get a path of file which imported module
every question was about how get path of module but not about it does anyone know how access it or get some normal way ?
My Module is used to get relative path but i cant get a folder in which is file using that module
I tried get Parent of Module and some os.path methods but None returned needed data
答案1
得分: 0
Use sys.argv[0]
, e.g.
def path_of_main_script():
return sys.argv[0]
英文:
Use sys.argv[0]
, e.g.
def path_of_main_script():
return sys.argv[0]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论