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

Removing option from optparse

Hello,

I'm trying to figure out if the following is a bug or if I'm using the
remove_option in the wrong way.

#!/usr/bin/env python
import optparse
parser = optparse.OptionParser()
parser.add_option("--test", help="This is a test option")
parser.remove_option('--test')
print parser.parse_args()

this will output:
(<Values at 0x6beb8: {'test': None}>, [])

If you execute the --help on the file above you will not see --test as
expected. I'm curious as to why parse_args is still returning this as
an option.

Thanks,
Gustavo
Jun 27 '08 #1
1 2629
Gu************@gmail.com schrieb:
Hello,

I'm trying to figure out if the following is a bug or if I'm using the
remove_option in the wrong way.

#!/usr/bin/env python
import optparse
parser = optparse.OptionParser()
parser.add_option("--test", help="This is a test option")
parser.remove_option('--test')
print parser.parse_args()

this will output:
(<Values at 0x6beb8: {'test': None}>, [])

If you execute the --help on the file above you will not see --test as
expected. I'm curious as to why parse_args is still returning this as
an option.
I'm guessing here - but it is *one* thing to disable an option for the
user because of whatever condition, and another to remove the options
default value that code could possibly rely on to work. So I'd say the
behavior is sane.

Diez
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam Smith | last post by:
I am using optparse for the commandline parsing for my programs. I was wondering if it is possible to detect if an option or option-arg has been specified on the commandline by the user or not....
9
by: Ritesh Raj Sarraf | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I'm using optparse module to parse all options and arguments. My program uses mostly "option arguments" hence my len(args) value is always...
3
by: Karlo Lozovina | last post by:
If I create a file with only one line: --- from optparse import OptionParser --- I get this when I try to run it from "DOS" prompt: Traceback (most recent call last): File "optparse.py",...
7
by: R. Bernstein | last post by:
optparse is way cool, far superior and cleaner than other options processing libraries I've used. In the next release of the Python debugger revision, I'd like to add debugger options: --help...
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...
8
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the...
1
by: Pupeno | last post by:
Hello, I am doing some extreme use of optparse, that is, extending it as explained on http://docs.python.org/lib/optparse-other-reasons-to-extend-optparse.html I have subclassed OptionParser and...
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...
4
by: Karthik Gurusamy | last post by:
Hi, I see that I can provide a default value for an option. But I couldn't find out any way if the user really entered the option or the option took that value because of default. A simple check...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.