How to get path of a .py script

David Necas (Yeti) yeti at physics.muni.cz
Wed Dec 11 14:22:27 EST 2002


On Wed, Dec 11, 2002 at 08:05:12PM +0100, Bernhard Herzog wrote:
> 
> Indeed. If the filename given to the Python interpreter is a symlink to
> the actual script, Python puts the directory containing the actual
> script into sys.path as the first item. So, sys.path[0] is usually
> enough.

But if the link contains ../ components, they also appear in
sys.path[0], which I don't call fully resolved.

And what's even funnier, when it's not just a single link,
but a link chain, you get just intermediate path after first
link resolved in sys.argv[0].

Yeti





More information about the Python-list mailing list