Removing option from optparse

G

GustavoTabares

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
 
D

Diez B. Roggisch

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top