How to set program name in Python? ($0 in Perl)

Steve Holden steve at holdenweb.com
Thu Nov 10 02:14:27 EST 2005


Fredrik Lundh wrote:
> Steve Holden wrote:
> 
> 
>>>Is there a way to set the program name in Python, similar to $0 in
>>>Perl?
>>>
>>>>From `man perlvar`:
>>>
>>>$0      Contains the name of the program being executed.  On some oper-
>>>               ating systems assigning to "$0" modifies the argument
>>>area that
>>>               the ps program sees.  This is more useful as a way of
>>>indicat-
>>>               ing the current program state than it is for hiding the
>>>program
>>>               you're running.  (Mnemonic: same as sh and ksh.)
> 
> 
>>import sys
>>print sys.argv[0]
> 
> 
> that *gets* the name, but assigning to sys.argv[0] doesn't *set* it (afaik).
> 
> setting the name involves overwriting the C level argv array, several large
> buckets of worms, and huge portability issues, and is thus better left to non-
> standard extensions.
> 
Indeed. My bad.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list