Using optparse

Peter Otten __peter__ at web.de
Thu Apr 23 14:13:54 CEST 2009


loial wrote:

> A shell script is passing parameters to my python script in the
> following format
> 
> -PARAM1 12345 -PARAM2 67890
> 
> Can I parse these with optparse  ? If so how?
> 
> I can't seem to get it to work. It seems to expect --PARAM1 and --
> PARAM2

You are out of luck. Quoting

http://docs.python.org/library/optparse.html

"""
There are many different syntaxes for options; the traditional Unix syntax
is a hyphen (“-“) followed by a single letter, e.g. "-x" or "-F". Also,
traditional Unix syntax allows multiple options to be merged into a single
argument, e.g. "-x -F" is equivalent to "-xF". The GNU project
introduced "--" followed by a series of hyphen-separated words,
e.g. "--file" or "--dry-run". These are the only two option syntaxes
provided by optparse.
"""

Peter



More information about the Python-list mailing list