Kikapi
Kikapi

Reputation: 369

Python character encoding returns incorrect value

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'

Upvotes: 1

Views: 263

Answers (2)

Zelldon
Zelldon

Reputation: 5516

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.

Upvotes: 0

Ward
Ward

Reputation: 2852

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

Upvotes: 3

Related Questions