What is the best way to handle a command line argument that includes an escape sequence like \n?

Steven Bethard steven.bethard at gmail.com
Wed Mar 2 19:35:41 EST 2005


Joe wrote:
> It appears that Python treats the comand line string as a raw string.
> 
> what is the best way to work around the issue?

You probably want to use str.decode with the encoding 'string_escape'[1]

py> s = r'\n\t'
py> s
'\\n\\t'
py> s.decode('string_escape')
'\n\t'

STeVe

[1]http://docs.python.org/lib/standard-encodings.html



More information about the Python-list mailing list