optparse escaping control characters
Hrvoje Niksic
hniksic at xemacs.org
Tue Aug 19 08:45:33 EDT 2008
wannymahoots at gmail.com writes:
> 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?
It has nothing to do with optparse, it's how Python prints strings:
$ python -c 'import sys; print sys.argv' '\t'
['-c', '\\t']
Note that you're not really passing a control character to Python,
you're passing a two-character string consisting of \ and t. When
representing the string inside a data structure, Python escapes the \
to avoid confusion with a real control character such as \t.
If you try printing the string itself, you'll see that everything is
correct:
$ python -c 'import sys; print sys.argv[1]' '\t'
\t
More information about the Python-list
mailing list