[New-bugs-announce] [issue5374] optparse special usage tokens conflict with formatting characters
report at bugs.python.org
Thu Feb 26 15:08:21 CET 2009
New submission from Andy Buckley <andy at insectnation.org>:
optparse's OptionParser takes a usage string as a constructor argument,
in which a "%prog" token is replaced with the executable name. Nice
idea, but the choice of a percent sign for token delimiter is
troublesome since it means that attempting to substitute any variables
into the usage string, e.g.
usage = """
%prog [options] foo bar ...
Some computed info: %s""" % myinfo
gives a ValueError:
ValueError: unsupported format character 'p' (0x70) at index 2
Maybe this ceases to be a problem with what I've heard about the
formatting re-design in Python 3.x, but it will probably continue to be
awkward for the 2.x series where the "%" operator still applies. Maybe
optparse could also use a safer token ("@prog", say), so that those of
use who would like to substitute variables into usage strings don't have
to artificially break our strings apart every time we use the program name?
components: Library (Lib)
title: optparse special usage tokens conflict with formatting characters
versions: Python 2.5
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce