【发布时间】:2013-09-07 19:50:19
【问题描述】:
我需要能够在我的代码中使用来自网站的复制+粘贴字符串。该网站的编码是 unicode (utf-8)。字符串
'''I’ve held others before'''
是复制+粘贴的,并且有一个“有趣”的撇号。当我尝试替换这个撇号时
my_string = '''I’ve held others before'''
my_string.replace('’', "'")
print(my_string)
我还是明白了
>>> I’ve held others before
而不是
>>> I've held others before
我不能使用带有有趣撇号的字符串,因为稍后在我的代码中它会给我这个错误:
'ascii' codec can't decode byte 0xe2 in position 2: ordinal not in range(128)
我尝试添加两者
my_string.decode('utf-8')
my_string.encode('utf-8')
但他们似乎什么也没做。有什么想法吗?
【问题讨论】:
-
您粘贴字符串的页面的编码是什么?
-
我认为是 unicode (utf-8)。 poemsource.com/love-poems.html