【问题标题】:Python error resolving ’Python错误解决'
【发布时间】:2016-06-27 08:27:03
【问题描述】:
str="First of all this isn’t one persons opinion, I promise you this is the worst movie ever. I feel like the other people saw a completely different movie. It starts off with a scene that would terrify any child 9 or under and only goes downhill from there. It’s about this kid named Norman that can talk to ghost or something. His weird and very unfunny uncle can also see ghost and warns him about some witches curse and zombies that are coming. I left after the zombies appeared because I couldn’t take any more of this awful movie. The movie was awful, but then the preview Frankenweenie came on and that looked awesome. I'm usually not a fan of Tim Burton but this looks really good. Do not see Paranorman!"

这是我的输入字符串。然而,Python 将其更改为当我 print str

First of all this isn\xe2\x80\x99t one persons opinion, I promise you this is the worst movie ever. I feel like the other people saw a completely different movie. It starts off with a scene that would terrify any child 9 or under and only goes downhill from there. It\xe2\x80\x99s about this kid named Norman that can talk to ghost or something. His weird and very unfunny uncle can also see ghost and warns him about some witches curse and zombies that are coming. I left after the zombies appeared because I couldn\xe2\x80\x99t take any more of this awful movie. The movie was awful, but then the preview Frankenweenie came on and that looked awesome. I'm usually not a fan of Tim Burton but this looks really good. Do not see Paranorman!

如何将 "\xe2\x80\x99t" 解析为 ’ ?

【问题讨论】:

标签: python-2.7


【解决方案1】:

好的,我发现了错误。你正在编码你的字符串 str 是 utf-8 这给了这个问题,检查下面的 sn-p

str="First of all this isn’t one persons opinion, I promise you this is the worst movie ever. I feel like the other people saw a completely different movie. It starts off with a scene that would terrify any child 9 or under and only goes downhill from there. It’s about this kid named Norman that can talk to ghost or something. His weird and very unfunny uncle can also see ghost and warns him about some witches curse and zombies that are coming. I left after the zombies appeared because I couldn’t take any more of this awful movie. The movie was awful, but then the preview Frankenweenie came on and that looked awesome. I'm usually not a fan of Tim Burton but this looks really good. Do not see Paranorman!"
print (str.encode('utf-8', 'ignore'))

现在的输出是

First of all this isn\xe2\x80\x99t one persons opinion, I promise you this is the worst movie ever. I feel like the other people saw a completely different movie. It starts off with a scene that would terrify any child 9 or under and only goes downhill from there. It\xe2\x80\x99s about this kid named Norman that can talk to ghost or something. His weird and very unfunny uncle can also see ghost and warns him about some witches curse and zombies that are coming. I left after the zombies appeared because I couldn\xe2\x80\x99t take any more of this awful movie. The movie was awful, but then the preview Frankenweenie came on and that looked awesome. I'm usually not a fan of Tim Burton but this looks really good. Do not see Paranorman!

将编码更改为ascii,它应该可以正常工作

print (str.encode('ascii', 'ignore'))

输出如下

First of all this isnt one persons opinion, I promise you this is the worst movie ever. I feel like the other people saw a completely different movie. It starts off with a scene that would terrify any child 9 or under and only goes downhill from there. Its about this kid named Norman that can talk to ghost or something. His weird and very unfunny uncle can also see ghost and warns him about some witches curse and zombies that are coming. I left after the zombies appeared because I couldnt take any more of this awful movie. The movie was awful, but then the preview Frankenweenie came on and that looked awesome. I'm usually not a fan of Tim Burton but this looks really good. Do not see Paranorman!

【讨论】:

    猜你喜欢
    • 2012-02-10
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 1970-01-01
    • 2021-11-24
    • 2015-11-02
    • 2016-06-01
    • 2017-12-04
    相关资源
    最近更新 更多