资讯科技及#039;s而不是它';python字符串中的s

资讯科技及#039;s而不是它';python字符串中的s,python,string,single-quotes,Python,String,Single Quotes,我的python字符串由和#039而不是“(单引号)。我目前的目标是扩展复合词,就像它是它是,没有到没有 “这对我来说太棒了。我已经服用了两周,在过去的一周里,我只有三次头痛,服用2泰诺后就消失了。我每天都有慢性头痛,无论吃什么都不会消失。我白天仍然有点困,但我知道这会好起来的。” 上面的陈述是我一直试图转换的句子的一个例子 有人能建议一种将其转换为字符串格式的方法吗 text = "This has been great for me. I've been on it for

我的python字符串由
和#039而不是“(单引号)。我目前的目标是扩展复合词,就像它是它是,没有到没有

“这对我来说太棒了。我已经服用了两周,在过去的一周里,我只有三次头痛,服用2泰诺后就消失了。我每天都有慢性头痛,无论吃什么都不会消失。我白天仍然有点困,但我知道这会好起来的。”

上面的陈述是我一直试图转换的句子的一个例子

有人能建议一种将其转换为字符串格式的方法吗

text = "This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better."
d_contraction = {"I'm":"I am","wouldn't":"would not","I've":"I have"}
updated_text = text.replace(''', "'") 
print(updated_text)
for k,v in d_contraction.items():
    updated_text = updated_text.replace(k,v) 
print(updated_text)
输出:

This has been great for me. I've been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that wouldn't go away no matter what I took. I'm still a little sleepy during the day, but I know that will get better.

This has been great for me. I have been on it for 2 weeks and in the last week I only had 3 headaches which went away with 2 Tylenol. I was having chronic daily headaches that would not go away no matter what I took. I am still a little sleepy during the day, but I know that will get better.

以上代码适用于您提供的文本。基本上,您必须创建一个包含所有可能的收缩示例的字典-它们将、它们等等。

您使用的是python2吗?如果是这样,请切换到python3,然后查看unicode处理。@match我只使用python3。这与unicode无关,它们只是HTML实体,@match。这段文字是HTML编码的。HTML解码它.HTML模块?呃-你完全正确-太早了,需要咖啡!