您如何显示当前正在运行的python模块的路径? [英] How do you show the path of the current running python module?
本文介绍了您如何显示当前正在运行的python模块的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何显示当前正在运行的python模块的路径?
如果将bla.py放在/Users/user/documents/python/
中,它将打印/Users/user/documents/python/bla.py
.
How do you show the path of the current running python module?
Which would print /Users/user/documents/python/bla.py
if bla.py was placed in /Users/user/documents/python/
.
推荐答案
如果您希望模块即使在导入时也知道其所在位置,则应该可以使用
If you want a module to know where it's at even when imported, you should be able to use
import sys
sys.modules[__name__].__file__
我知道这包括我的linux系统上的绝对路径,但我听说它说它不在Windows上.
I know this includes the absolute path on my linux system but I've heard it said that it doesn't on Windows.
这篇关于您如何显示当前正在运行的python模块的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文