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
  • 71,966
  • 47
  • 171
  • 241

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
  • 68,820
  • 20
  • 127
  • 125
8
import os
print os.path.abspath(__file__)
systempuntoout
  • 71,966
  • 47
  • 171
  • 241