[通告] 本论坛迁移啦~请前往位于 https://forum.archlinuxcn.org/ 的新论坛。所有帖子和参与的用户都已经迁移。
您正在访问的是原 bbs.archlinuxcn.org 的静态存档。本页面的新地址位于 https://forum.archlinuxcn.org/t/topic/9210。
页次: 1
使用 python 2.7.13
问题是这样的:
从文本文档中读取字符串
In [1]: !cat ./mfkd
周
In [2]: with open('mfkd') as f:
...: s = f.read()
...:
In [3]: s
Out[3]: '\xe5\x91\xa8'请问如何将字符串 s 转换为 r'\xe5\x91\xa8'?
最近编辑记录 alexxey (2017-02-09 17:31:20)
离线
发现可以这样:
s.encode('string-escape')或
repr(s)离线
页次: 1