467,188 Members | 1,484 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,188 developers. It's quick & easy.

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
  • viewed: 2210
Share:
1 Reply
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Ritesh Raj Sarraf | last post: by
3 posts views Thread by Karlo Lozovina | last post: by
7 posts views Thread by R. Bernstein | last post: by
reply views Thread by Steven Bethard | last post: by
4 posts views Thread by Mathias Waack | last post: by
4 posts views Thread by Karthik Gurusamy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.