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

Joe JoeSalmeri at hotmail.com
Wed Mar 2 20:18:33 EST 2005


Steve,

THANKS!  That is exactly what I was looking for but unable to find.

Joe

"Steven Bethard" <steven.bethard at gmail.com> wrote in message 
news:ocadne0P2fh3xrvfRVn-rQ at comcast.com...
> 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