获取模块内部文件的路径。

huangapple go评论59阅读模式
英文:

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]

huangapple
  • 本文由 发表于 2023年5月7日 01:18:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76190174.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定