[Python-3000] Move argv[0]? (Re: Unicode and OS strings)

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Sep 17 05:58:18 CEST 2007


Larry Hastings wrote:
> If nothing else, at least we could fix the proviso for argv[0]: "(it is 
> operating system dependent whether this is a full pathname or not)."  

It's actually worse than that -- you're entirely at the
mercy of whatever made the exec() call as to whether it's
a meaningful path at all.

Most programs are courteous enough to make sure it's at
least a relative path to the executable being run, but
you can't rely on that.

I'm not sure munging argv[0] to an absolute path is the
right thing to do, if it's to be regarded as a low-level
thing. A program wanting low-level access to argv might
want to know exactly what was passed to exec() for some
reason.

A separate sys.absolute_path_to_executable() or
something might be better.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | Carpe post meridiem!          	  |
Christchurch, New Zealand	   | (I'm not a morning person.)          |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-3000 mailing list