1

I'm using Python 2.7.11 , I get a wrong value when getting decimal value of a character from extended ascii table

# -*- coding: utf-8 -*-
str="è"
print(ord(str[0])) #prints 232 decimal

but the value of this char is 138 decimal (http://www.asciitable.com/)

When i remove the coding utf-8 line i get this error SyntaxError: Non-ASCII character '\xe8'

2
  • 1
    What version of Python are you using? Commented Jun 14, 2016 at 11:13
  • Added to the question, sorry. Commented Jun 14, 2016 at 11:14

2 Answers 2

3

UTF-8 is not extended asci. If you check the UTF-8 table here, you will see that 232 is indeed the correct ordinal.

Also, I recommend Joel on software's UTF-8 article

Sign up to request clarification or add additional context in comments.

Comments

0

The character è referes in the unicode/utf-8 encoding to 0x00E8 which means 232.

See this reference

The character is contained in the extended ASCII see this
question for the extended ASCII and python.

3 Comments

Which encoding should I use, so the ord() will return 138?
Try ## -*- coding: latin-1 -*-
It returns the same value. (232d)

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.