有一个文件内容是类似于这样子的: ID = "\"" alphanums* "\"";读出文件后,输出的字符串就是这样带有斜杠的请问读出文件之后,怎么让里面的转义字符\n,\",\r,具有转义功能呢?手动写一个函数匹配转义吗?
欢迎选择我的课程,让我们一起见证您的进步~~
Using codecs, it looks like this:
codecs
# python3 code import codecs print(codecs.getdecoder("unicode_escape")('first line\nsecond line\n\"\"\"')[0])
Result:
first line second line """
Questions I answered: Python-QA
Using
codecs
, it looks like this:Result:
Questions I answered: Python-QA