Easier way to get the "here" path?

bukzor workitharder at gmail.com
Mon Jul 28 19:34:40 CEST 2008


On Jul 26, 9:19 am, Andrew <alif... at gmail.com> wrote:
> 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

As you can see above, I get the wrong think if I do that. It's very
strange that we're getting different things. I'm using python 2.4,
maybe it was updated in 2.5?



More information about the Python-list mailing list