optparse escaping control characters

wannymahoots at gmail.com wannymahoots at gmail.com
Tue Aug 19 08:35:27 EDT 2008


optparse seems to be escaping control characters that I pass as
arguments on the command line.  Is this a bug?  Am I missing
something?  Can this be prevented, or worked around?

This behaviour doesn't occur with non-control characters.

For example, if this program (called test.py):
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-d", dest="delimiter", action="store")
(options, args) = parser.parse_args()
print options

is run as follows:
python test.py -d '\t'

it outputs:
{'delimiter': '\\t'}

i.e. the \t has had an escape character added to give \\t.




More information about the Python-list mailing list