[Tutor] finding directory of self

Wayne Werner waynejwerner at gmail.com
Tue Mar 29 02:16:41 CEST 2011

On Mon, Mar 28, 2011 at 6:43 PM, Rance Hall <ranceh at gmail.com> wrote:

> I had been doing this under windows:
> import os
> import sys
> osname = os.name
> pathtocfg = os.path.dirname(sys.argv[0])
> configfileloc = os.path.abspath(pathtocfg)
> os.chdir(configfileloc)
> to set the directory of all subsequent file lookups in a script.
> It worked underwindows because the shortcuts have a "Start In"
> directory listing.
> I need something for Linux use that does not care about a symlink that
> would be used to start the script.
> The above code finds the directory the symlink is in.
> I'm actually not suprised by this, it is what I expected, I just don't
> understand how to fix it.
> How can I do something similar to this, but find the "real" dir?
> Perhaps one of the other sys.argv arguments?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110328/ef4cbd97/attachment.html>

More information about the Tutor mailing list