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?

Recommended Answers

All 3 Replies

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

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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.