Create a backslash-escaped version of a string?

boblatest boblatest at googlemail.com
Mon Feb 8 06:14:40 EST 2010


Hello,

I'd like to have control characters in a string to be converted to
their backslash-escaped counterparts. I looked in the encoders section
of the string module but couldn't find anything appropriate. I could
write it myself but I'm sure something of the sort exists. The
hypothetical method "c_escaped()" would work like this:

>>> a="abc\rdef"
>>> print a.c_escaped()
abc\rdef
>>>

Thanks,
robert



More information about the Python-list mailing list