我的代码:
'''
Content of Hello.txt is only -> \251
Actually \251 represents ©
'''
prefix = "PREFIX"
suffix = "SUFFIX"
f = open('Hello.txt')
d = f.read()
f.close()
print prefix+d+suffix 我的问题是,它打印PREFIX\251SUFFIX,但实际上我希望它打印前缀c后缀
根据How to convert octal escape sequences with Python,我尝试了d.decode('utf-8'),但问题仍然是一样的。
发布于 2015-02-03 12:35:39
您需要将字符串澄清为python的unicode,您可以如下所示使用unicode函数:
>>> print unicode('PREFIX\251SUFFIX','unicode-escape')
PREFIX©SUFFIXhttps://stackoverflow.com/questions/28299070
复制相似问题