[Tutor] optparse example
Don Jennings
dfjennings at gmail.com
Mon Sep 22 16:53:55 CEST 2008
On 9/22/08, Tasos Latsas <tlatsas2000 at gmail.com> wrote:
> Hello list,
> I tried the optparse example from the python library reference and it
> doesn't seem to work..what am I doing wrong?
> I keep getting the "incorrect number of arguments" message although i
> use the correct number..
Actually, you aren't using the correct number of arguments for the
code as written. This line:
if len(args) != 1:
parser.error("incorrect number of arguments")
checks to see if the arguments, not to be confused with the options,
are greater than one. So, one way you might call the script would be:
python parser.py somefile.txt
Take care,
Don
More information about the Tutor
mailing list