optparse

T

Torsten Mohr

Hi,

i use the module optparse to parse the command line:

------example
#! /usr/bin/python

import optparse

parser = optparse.OptionParser()

parser.add_option("-v", "--verbose",
dest = 'verb',
help = 'be loud',
action = 'store_true',
default = 'store_false')

(opts, args) = parser.parse_args()

print "opts", opts
print "args", args
------example

If i call it without any parameters i get:

opts {'verb': 'store_false'}
args []


I would rather like to see the actual value False in "opts",
did i use some wrong parameters somewhere? I can't imagine
that this is the wanted behaviour of optparse.


Thanks for any hints,
Torsten.
 
T

Torsten Mohr

Hi,
If i call it without any parameters i get:

opts {'verb': 'store_false'}
args []

If i call it with parameter -v i get:

../script.py -v

opts {'verb': True}
args []


I wonder what's wrong here.


Best regards,
Torsten.
 
M

Marc 'BlackJack' Rintsch

parser.add_option("-v", "--verbose",
dest = 'verb',
help = 'be loud',
action = 'store_true',
default = 'store_false')

(opts, args) = parser.parse_args()

print "opts", opts
print "args", args
------example

If i call it without any parameters i get:

opts {'verb': 'store_false'}
args []


I would rather like to see the actual value False in "opts", did i use
some wrong parameters somewhere?

if you want `False` as default you should actually use `False` and not
the string 'store_false'.

Ciao,
Marc 'BlackJack' Rintsch
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top