Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > optparse and negative numbers as positional arguments

Reply
Thread Tools

optparse and negative numbers as positional arguments

 
 
Tomi Silander
Guest
Posts: n/a
 
      04-05-2005
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.
 
Reply With Quote
 
 
 
 
Grant Edwards
Guest
Posts: n/a
 
      04-05-2005
On 2005-04-05, Tomi Silander <(E-Mail Removed)> 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...
 
Reply With Quote
 
 
 
 
Tomi Silander
Guest
Posts: n/a
 
      04-06-2005
Grant Edwards wrote:

> On 2005-04-05, Tomi Silander <(E-Mail Removed)> 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.
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      04-06-2005
On 2005-04-06, Tomi Silander <(E-Mail Removed)> wrote:
> Grant Edwards wrote:
>
>> On 2005-04-05, Tomi Silander <(E-Mail Removed)> 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Greedy parsing of argparse/positional arguments Johannes Bauer Python 0 11-20-2012 10:02 AM
optparse: Arguments as Arguments Unexpectedness Ben Woodcroft Ruby 2 05-20-2009 12:49 PM
Understanding (and getting rid) of optparse.py:668: FutureWarning:%u/%o/%x/%X of negative int will return a hofer Python 2 09-26-2008 05:41 PM
extra positional arguments before optional parameters syntax MisterWilliam Python 1 06-18-2008 09:34 PM
DVD Verdict reviews: LAST EXILE: POSITIONAL PLAY (VOLUME 2) and more! DVD Verdict DVD Video 0 04-29-2004 09:05 AM



Advertisments