【发布时间】:2013-11-09 19:01:02
【问题描述】:
如何在字符串中替换这些字符:r'\xb0' 与 r'\260',我已经尝试过:
test = u'\xb0C'
test = test.encode('latin1')
test = test.replace(r'\xb0', r'\260')
但它不起作用。问题是,我必须将数据以八进制格式(例如'\260C')而不是十六进制格式等写入文件。
【问题讨论】:
-
你不想替换
r'\xb0'是吗?您要替换 字符,而不是 4 个字符的序列。.replace('\xb0', r'\260')会更合适。
标签: python unicode replace character