optparse and negative numbers as positional arguments

T

Tomi Silander

Hi,
this must have been asked 1000 times (or nobody is as stupid as me),
but since I could not find the answer, here is the question.

My program mitvit.py:
--------------
import optparse
optparse.OptionParser().parse_args()
--------------
gives me

$ python2.4 ./mitvit.py -1.1
usage: mitvit.py [options]

mitvit.py: error: no such option: -1.1

How is one supposed to give negative numbers as positional arguments
when using optparse?

ts.
 
G

Grant Edwards

this must have been asked 1000 times (or nobody is as stupid as me),
but since I could not find the answer, here is the question.
[...]

$ python2.4 ./mitvit.py -1.1

[optparse error]
How is one supposed to give negative numbers as positional arguments
when using optparse?

./mitvit.py -- -1.1
 
T

Tomi Silander

Grant said:
./mitvit.py -- -1.1

Thank you,
this works. I saw it in the source, but apparently did not properly pay
attention; all the args after "--" are considered positional if I read
this right.

ts.
 
G

Grant Edwards

this works.

Yes, I know. :)
I saw it in the source, but apparently did not properly pay
attention; all the args after "--" are considered positional
if I read this right.

That's the way it's traditionally been done. I just assumed
that optparse did it that way, and when I tried it with
optparse it seemed to work the same. It's not mentioned in the
optparse documentation anywhere (it probably should be).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top