0

Got some issues with ord() command and Unicode.

I want the decimal number of the entered ASCII letters.

For Example:

ord('ÄÖÜ') brings me these values: [195, 132, 195, 150, 195, 156]

  • [195,132] = Ä
  • [195,150] = Ö
  • [195,156] = Ü

This is what i want:

  • [196] = Ä
  • [214] = Ö
  • [220] = Ü

Any clues ?

4

2 回答 2

2

您需要 Unicode 代码点,而不是 UTF-8 编码中的字节:

>>> mystring = u'ÄÖÜ'
>>> [ord(c) for c in mystring]
[196, 214, 220]
于 2015-11-06T18:17:25.993 回答
1

这对我有用:

>>> [ord(i) for i in unicode('ÄÖÜ','utf-8')]
[196, 214, 220]
于 2015-11-06T18:40:37.060 回答