473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

optparse and negative numbers as positional arguments

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
3 2446
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Hans-Joachim Widmaier | last post by:
I was really pleased when the Optik module found its way into the standard Python battery compartment, as it matched all my option parsing requirements. But, as always, there's really nothing that...
7
by: Henry Ludemann | last post by:
I've been writing an optparse alternative (using getopt) that is at a stage where I'd be interested in people's opinions. It allows you to easily creating command line interfaces to existing...
0
by: Steven Bethard | last post by:
I feel like I must be reinventing the wheel here, so I figured I'd post to see what other people have been doing for this. In general, I love the optparse interface, but it doesn't do any checks...
4
by: rick | last post by:
Consider the following piece of code: parser = optparse.OptionParser(usage="usage: %prog <input filename> <output filename", add_help_option=False) parser.add_option("-d", type="string",...
3
by: Rocky Zhou | last post by:
I wonder is there any way to make the wrapper program can wrap options && arguments for the the subprocess/command the wrapper will execute? by getopt or optparse module? This is something...
4
by: Mathias Waack | last post by:
We've integrated python into a legacy application. Everything works fine (of course because its python;). There's only one small problem: the application reads the commandline and consumes all...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
2
by: hofer | last post by:
Hi, I get following warning with a python script: optparse.py:668: FutureWarning: %u/%o/%x/%X of negative int will return a signed string in Python 2.4 and up my code:
1
by: John O'Hagan | last post by:
Hello, I've recently found it convenient to do something like this: options = optparse_function(sys.argv) ##print options => ##{option_one:4, option_two:, option_three:'/home/files'} ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.