How do you show the path of the current running python module? [duplicate]
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__)
精彩评论