How to set program name in Python? ($0 in Perl)
bokr at oz.net
Thu Nov 10 23:14:32 CET 2005
On Thu, 10 Nov 2005 08:06:27 +0100, "Fredrik Lundh" <fredrik at pythonware.com> 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
>that *gets* the name, but assigning to sys.argv 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-
OTOH, if the intent is just to set a value for subsequent getting by way of
sys.argv, isn't sys.argv an ordinary list?
>>> import sys
>>> sys.argv = '<interactive>'
More information about the Python-list