optparse and negative numbers as positional arguments

Discussion in 'Python' started by Tomi Silander, Apr 5, 2005.

  1. 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.
     
    Tomi Silander, Apr 5, 2005
    #1
    1. Advertising

  2. On 2005-04-05, Tomi Silander <> 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...
     
    Grant Edwards, Apr 5, 2005
    #2
    1. Advertising

  3. Grant Edwards wrote:

    > On 2005-04-05, Tomi Silander <> 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.
     
    Tomi Silander, Apr 6, 2005
    #3
  4. On 2005-04-06, Tomi Silander <> wrote:
    > Grant Edwards wrote:
    >
    >> On 2005-04-05, Tomi Silander <> 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?
     
    Grant Edwards, Apr 6, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. prem_eda
    Replies:
    5
    Views:
    7,928
    Pieter Hulshoff
    Oct 11, 2004
  2. MisterWilliam
    Replies:
    1
    Views:
    327
    George Sakkis
    Jun 18, 2008
  3. hofer
    Replies:
    2
    Views:
    909
    hofer
    Sep 26, 2008
  4. Ben Woodcroft
    Replies:
    2
    Views:
    172
    Ben Woodcroft
    May 20, 2009
  5. Johannes Bauer
    Replies:
    0
    Views:
    164
    Johannes Bauer
    Nov 20, 2012
Loading...

Share This Page