0

Hi
I am using Option parser for creating a command line application .
I am able to parse command line options.
I have a command for listing the contents of a folder.
which goes like this

python main.py --listContents

When I give this I get an error
error: --listContents option requires an argument

when I give the same command with
python main.py --listContents xxxx
it runs fine no matter what value is xxxx
Why does not it work without xxxx?

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by adam1122
0

Traditionally, options beginning with -- are commands and do require arguments. are you able to use -listContents or /listContents instead?

0

Traditionally, options beginning with -- are commands and do require arguments. are you able to use -listContents or /listContents instead?

Hey Thanks for the reply and yes I am able to run it using -listContents when I have my option parser as
c.add_option('-l','--listContents',help='To list all Contents use --listContents')

Is there way I can make it work using --listContents?

0

You're able to use -listContents because it's picking up the -l part. You should be able to replace 'istContents' with anything and get the same results. It's picking up 'istContents' as the option of the argument '-l'.

The option parser in Python uses Unix style.

Gotta run so I can't finish this thought right now but hope that helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.