os.path.dirname(sys.argv) always returns nothing
wafflesouffle at gmail.com
Tue Aug 9 15:07:23 CEST 2011
On Aug 2, 12:57 am, Gregory Ewing <greg.ew... at canterbury.ac.nz> wrote:
> Thijs Engels wrote:
> > argv returns the name of the current file (string), but no path
> > information if I recall correct.
> It's the path that was used to specify the script by whatever
> launched it, so it could be either absolute or relative to
> the current directory.
>From the docs there are a couple of special cases: "If the command was
executed using the -c command line option to the interpreter, argv
is set to the string '-c'. If no script name was passed to the Python
interpreter, argv is the empty string."
So if you're running in a python interpreter compiled into an
executable which doesn't initialise argv, that's another case where
things won't go as expected.
That's probably not relevant in this case, but I've certainly been
bitten by it in the past.
More information about the Python-list