开发者

How do you show the path of the current running python module? [duplicate]

This question already has answers here: 开发者_运维百科 How to retrieve a module's path? (23 answers) Closed 7 years ago.

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__

I know this includes the absolute path on my linux system but I've heard it said that it doesn't on Windows.


import os
print os.path.abspath(__file__)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜