Python error resolving ’

V Sree Harissh
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!"

This is my input string. Python however changes it to when i 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!

How do I resolve "\xe2\x80\x99t" to ?

enter image description here

sameera sy

Okay I found the error. You are encoding your string str is utf-8 which is giving this problem, check the snippet below

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'))

Now output of this is

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!

Change the encoding to ascii and it should work as expected

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

The output is as below

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!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related