Translate escaped characters in a string
Josiah Carlson
jcarlson at uci.edu
Sat Apr 3 02:46:26 EST 2004
> I have an application that reads the arguments sent to the script. If
> an user enters a text like "Line 1\nLine2" (\n is slash+n, and not
> LF), I would like to use \n and other supported escape sequences when
> I write the text to a file.
>
> Is there a way to do this, other than writing my own parser?
I know there's an easier way to do it, but the below works...
>>> import encodings
>>> print encodings.codecs.escape_decode('hello\\nworld')[0]
hello
world
>>>
If the stings are escaped normally, the above will produce what you want.
- Josiah
More information about the Python-list
mailing list