By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,525 Members | 1,623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,525 IT Pros & Developers. It's quick & easy.

optparse and negative numbers as positional arguments

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2005-04-05, Tomi Silander <ts******@hiit.fi> wrote:
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

--
Grant Edwards grante Yow! .. over in west
at Philadelphia a puppy is
visi.com vomiting...
Jul 18 '05 #2

P: n/a
Grant Edwards wrote:
On 2005-04-05, Tomi Silander <ts******@hiit.fi> wrote:

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


./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.
Jul 18 '05 #3

P: n/a
On 2005-04-06, Tomi Silander <ts******@hiit.fi> wrote:
Grant Edwards wrote:
On 2005-04-05, Tomi Silander <ts******@hiit.fi> wrote:
How is one supposed to give negative numbers as positional
arguments when using optparse?


./mitvit.py -- -1.1


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).

--
Grant Edwards grante Yow! .. are the STEWED
at PRUNES still in the HAIR
visi.com DRYER?
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.