11

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/.

systempuntoout
  • 69,075
  • 45
  • 164
  • 239

2 Answers2

14

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.

aaronasterling
  • 65,653
  • 19
  • 122
  • 125
8
import os
print os.path.abspath(__file__)
systempuntoout
  • 69,075
  • 45
  • 164
  • 239