New submission from Andy Buckley <a...@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)
messages: 82755
nosy: andybuckley
severity: normal
status: open
title: optparse special usage tokens conflict with formatting characters
type: behavior
versions: Python 2.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue5374>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to