argv[0] manipulation

Bengt Richter bokr at oz.net
Wed Dec 11 14:03:51 EST 2002


On 11 Dec 2002 18:46:19 GMT, bokr at oz.net (Bengt Richter) wrote:

>On Wed, 11 Dec 2002 12:02:52 +0000, P_spam_ at draigBrady.com wrote:
>
>>Hi,
>>
>>I had the idea to select debugging mode
>>in my application depending on the contents of argv[0].
[...]
>What's wrong with the typical option usage of -d or --debug or whatever suits you?
>E.g.,
[...]
>    import sys
>    args = sys.argv[1:]
>    opt_debug = args and args[0].lower() in ['-d','--debug']
                                 ^^^^^^^^-- actually, leave this out to be more typical, sorry.
>    if opt_debug:
>        args.pop(0)     # remove the opt arg
>    test(opt_debug, args)      

Regards,
Bengt Richter



More information about the Python-list mailing list