[Tutor] convert '\\t' to '\t'
Poor Yorick
gp@pooryorick.com
Thu Jan 16 11:19:01 2003
Hy Python wrote:
> I understand this.
> But what I really want to do is
> convert things like "\\n","\\r","\\s", "\\x" to "\n", "\r", "\s", "\x"
> So, is there a universal way to convert "\\" to "\"
Your question is still confusing because "\\n" already IS "\n" when you
print it. Do mean that you have a text which displays "\\n" and you
want that text to display "\n"? In that case something like this would
work:
>>> text = "he\\\\nllo"
>>> print text
he\\nllo
>>> text2 = text.replace('\\\\n', '\\n')
>>> print text2
he\nllo
>>>
Poor Yorick
gp@pooryorick.com