Easier way to get the "here" path?
Andrew
alif016 at gmail.com
Sat Jul 26 12:19:45 EDT 2008
bukzor wrote:
>>>> from os.path import abspath, realpath
>>>> realpath(path.__file__.rstrip("c"))
>>>>
> '/home/bgolemon/python/symlinks/path.py'
>
>>>> realpath(abspath(path.__file__.rstrip("c")))
>>>>
> '/home/bgolemon/python/symlinks/symlinks/path.py'
> --
> http://mail.python.org/mailman/listinfo/python-list
>
I find it interesting that I get something different:
In [1]: import path
path.pyc
In [2]: path.__file__
Out[2]: 'path.pyc'
In [3]: path.__file__.rstrip("c")
Out[3]: 'path.py'
In [4]: from os.path import abspath, realpath
In [5]: realpath(path.__file__.rstrip("c"))
Out[5]: '/home/andrew/sym/sym/path.py'
In [6]: realpath(abspath(path.__file__.rstrip("c")))
Out[6]: '/home/andrew/sym/sym/path.py'
I get the same thing for realpath() and realpath(abspath())
It seems to me you can just use:
In [1]: import path
path.pyc
In [2]: from os.path import abspath
In [3]: realpath(path.__file__.rstrip("c"))
Out[3]: '/home/andrew/sym/sym/path.py'
By the way, I am in /home/andrew/sym and path is symlinked from
/home/andrew/sym/sym/path.py to /home/andrew/sym/path.py
--
Andrew
More information about the Python-list
mailing list