convert string to raw string?
Steven Bethard
steven.bethard at gmail.com
Mon Dec 6 11:36:20 EST 2004
Duncan Booth wrote:
> If you are getting input from the user, then unless you are doing some
> processing on it to interpret escape sequences the chances are you already
> have what you need to use as a regular expression. If you *are*
> interpreting escape sequences then the answer is you need to not do that
> since the operation isn't really reversible.
If you are interpreting escape sequences, you probably want
string.decode or string.encode:
>>> '\\n\\r'.decode('string_escape')
'\n\r'
>>> '\n\r'.encode('string_escape')
'\\n\\r'
Steve
More information about the Python-list
mailing list