首页 > 代码库 > python中处理读入文件中的转义字符

python中处理读入文件中的转义字符

本文最初发表于 http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=4143291&page=1#pid24220123


Hello

World!

In [3]: s.encode(‘string_escape‘)

Out[3]: ‘Hello\\nWorld!‘

In [4]: Out[3].decode(‘string_escape‘)

Out[4]: ‘Hello\nWorld!‘

Not *quite* what you asked for, but it ought to be close enough.