Possible duplicate:
Handle escape sequences in a string in Python
If I get this line, for example, from a web form:
'\n test'
The notation '\n'
will not be interpreted as a line break. How do I parse this line so that it becomes a line break?
Of course, I can use replace
, split
, re
, etc. to do it manually.
But perhaps there is a module for this, since I do not want me to be forced to process all \something
notation manually.
I tried turning it into bytes and then using str
as a constructor, but this does not work:
>>> str(io.BytesIO(ur'\n'.encode('utf-8')).read()) '\\n'
e-satis
source share