0

Let's say I'm calling a python file from this directory:

 $ pwd
 $ my_dir1/path1/
 $ python mydir2/path2/my_code.py

Note that my_code.py is stored at another directory. What I want to do is in my_code.py determine where it is called. Namely I want it to display my_dir1/path1/.

What code should I put in my_code.py.

neversaint
  • 60,904
  • 137
  • 310
  • 477

1 Answers1

2

You're looking for the __file__ global variable.

> cat mydir2/path2/my_code.py
print __file__
> python mydir2/path2/my_code.py
mydir2/path2/my_code.py
lextoumbourou
  • 463
  • 4
  • 7