argv[0] manipulation
Bernhard Herzog
bh at intevation.de
Sun Dec 15 08:13:55 EST 2002
Jp Calderone <exarkun at meson.dyndns.org> writes:
> On Sat, Dec 14, 2002 at 05:55:13PM +0100, Bernhard Herzog wrote:
> > [snip]
> > Then the documentation is wrong, or at least misleading :)
> > [snip]
>
> import sys
> sys.argv.insert(0, 'A Man, A Plan, A Canal Panama')
> import yourModule
> yourModule.function() # Hope it doesn't depend on sys.argv[0]
We were talking about a script, not a module that doesn't know who's
importing it. A script that modifies sys.argv obviously has to be
careful when referring to it later. A module should normally make no
assumptions about sys.argv and simply refer to __file__ if it needs to
find out which file it was loaded from.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://mapit.de/
More information about the Python-list
mailing list