Easier way to get the "here" path?

Andrew alif016 at gmail.com
Sat Jul 26 18:02:14 CEST 2008

bukzor wrote:
> I have to go into these convulsions to get the directory that the
> script is in whenever I need to use relative paths. I was wondering if
> you guys have a better way:
> ...
If you just need the current path (where it is executed) why not use 
which returns a string of the absolute path to the module being executed.

$ echo "print __file__" > path.py
$ ipython
In [1]: import path

In [2]: import os

In [3]: os.path.join(os.getcwd(), path.__file__.rstrip("c"))
Out[3]: '/home/andrew/path.py'

More information about the Python-list mailing list