Problem with optparser or In
Peter Otten
__peter__ at web.de
Wed Feb 25 05:25:47 EST 2004
Florian Lindner wrote:
> Hi,
> I'm not sure where the problems lies...
> I'm using optparse and I've a option defined:
>
> parser.add_option("-t", "--type", action="callback",
> callback=option_callback, type="string")
>
> def option_callback(option, opt, value, parser, *args, **kwargs):
Change to
if (str(option) == "-t/--type") and (value in ("mailbox", "ftp")):
> if (str(option) == "-t/--type") and (opt in ("mailbox", "ftp")):
> print "Error!"
> else:
> parser.values.type = opt
>
> This should print error if the commandline is "--type=ftp" or
> "--type=mailbox" (same for the short args).
> But it never gets till Error... Although opt contains "mailbox" or "ftp".
> What's wrong there?
In such cases the poor man's debugger aka print statement is your friend.
print opt
would reveal that opt contains the actual option and value - surprise,
surprise -the value.
Peter
More information about the Python-list
mailing list