473,385 Members | 1,555 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,385 software developers and data experts.

How to send negative value arguments for command line application?

I have created a piece of python code; however, I want to execute it from the command line with some arguments and options. What I have so far works ok (with the exception that i CANNOT enter in negative values for the arguments -- and i need to be able to!) How can i better write this code?

What i enter on the command line:

C:\...>mycode.py arg1 arg2 arg3 -o filename -p filename -q filename (this is 3 arguments and 3 options)

What my code does (works with exception of negatives):

import sys
parser=optparse.OptionParser()

parser.add_option("--value1",dest"val1")
parser.add_option("--value2",dest"val2")
parser.add_option("--value3",dest"val3")

parser.add_option("-o",action="store",type="string",dest="opt1")
parser.add_option("-p",action="store",type="string",dest="opt2")
parser.add_option("-q",action="store",type="string",dest="opt3")

opts,args=parser.parse_args()


Help with this please...Again, I want to correctly do the arguments and options on the command line and be able to input negative values for an argument if needed. Again, what i have works (except for negative values)....anyone know a better way?
Dec 2 '10 #1
2 2794
dwblas
626 Expert 512MB
AFAIK there is no way to tell the difference between an option and a negative number, so you would have to either assume that non-options are negative numbers, or check with isdigit(), or come up with something like -neg and then the negative number.
Dec 2 '10 #2
dwblas
626 Expert 512MB
If you come up with a good solution to this please post it as this is something that comes up from time to time.
Dec 3 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Edward WIJAYA | last post by:
Hi, I am new to Python, and I like to learn more about it. Since I am used to Perl before, I would like to know what is Python equivalent of Perl code below: $filename = $ARGV;
1
by: Andrew McCall | last post by:
Hi Folks, I am building an application under multiple OS's, and I wanted to give my application For example, the test application I am working on is a calculator and I would like to have a...
0
by: h112211 | last post by:
Hi all, I'm using the Windows version of Python 2.4.3 and everything worked okay until I installed PyGreSQL. Well, in fact the installation went fine, but when I try to run my script from IDLE I...
0
by: h112211 | last post by:
Hi, Does anyone have any clues why I can import a module (pgdb) from the python command line, but trying to run a script doing it from IDLE I get "ImportError: DLL load failed: The specified...
13
by: Pieter Edelman | last post by:
Hi, I'm currently writing a command-line program in Python, which takes commands in the form of: ../myprog.py ARGS So pretty standard stuff. In my case, ARGS is a list of image files. One...
1
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I am writing a command line app, I have a question that's driving me crazy: Is it possible to update a printed line without having to write a new line, so that, for example, I could achieve...
2
by: Mick Duprez | last post by:
Hi All, I've installed Python 2.5 on a number of machines but on one I'm having problems with the CLI. If I fire up the 'cmd' dos box and type 'python' I get a line of gibberish and it locks up...
4
by: Rahul | last post by:
My python command line seems messed up. I can't seem to be able to use my backspace key nor my arrow keys. I only get control characters: ^[[A^[[D^[[D^[[D^[[C^[[C^[[C etc. I access my Linux...
4
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I am writing a command line application and I would like to implement a functionality similar to the "!" command in ftp.exe (that comes with most windows distros) so that I can leave my...
4
by: fang | last post by:
Dear all: The mouse cannot be responded in the windows of python(command line) and cut and paste cannot be done. ctrl c and ctrl v do not work. But they do work in IDLE. please teach me about...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.