1
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

6
  • i ran it, It doesn't give anything of that sort ideone.com/MoAv6v Commented Jun 27, 2016 at 8:31
  • Please check the picture in the question Commented Jun 27, 2016 at 8:36
  • You are probably using python3 and what you see is unicode. Commented Jun 27, 2016 at 8:38
  • I'm using Python 2.7.11 with Anaconda Commented Jun 27, 2016 at 8:39
  • Ok then I dont really know, but its the same as here: stackoverflow.com/questions/27996448/… Commented Jun 27, 2016 at 8:40

1 Answer 1

2

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!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.