sys.argv is munging my command line options

Chris Allen ca.allen at gmail.com
Wed Aug 29 15:11:54 EDT 2007


The command line syntax for my program is as follows:

action key=value key=value...

Where action is a required string (ie. 'backup', 'init', 'restore',
etc) and the program can accept one or more key value pairs.  I know
this syntax isn't standard, but I think it works great for my program
as each key can override an identically named field in a configuration
file, that way the user doesn't have to have two different syntaxes to
do the same thing.  I could do this with --key value, but key=value is
cleaner IMHO because it matches the config file syntax.

But I'm running into a problem with this which is that sys.argv splits
my key=value options.  I need to know the option associations, and
there's no way to know this by inspecting sys.argv.  Can I get access
to the command line string as python saw it before it split it into
sys.argv or is there another way?  Thanks.




More information about the Python-list mailing list