How to input unicode character and get its numeric value

Greg Tzikas

I am trying to take a file and remove all characters that are not in the greek language. We found the unicode values for the alphabet, 880 - 1023, and were able to print out the correct characters with a simple print(unichr(880)) line. The problem is when running this code

greek ='ÏÎ' 
for c in greek:
    if(unichr(c) >= 880 and unichr(c) <= 1023):
        print(c)

Is there a way to enter any letter or symbol that will return a unicode value. We have tested with values inside of the greek range and outside and still get the same error, UnicodeDecodeError: 'ascii' codec cannot decode byte 0xc3 in position 0: ordinal not in range(128)

tdelaney

You have several problems. Assuming this is python 2 (since there is no unichr in python 3 you'd get a different error) your first problem is that you didn't initialize a unicode string in the first place.

>>> greek ='ÏÎ' 
>>> len(greek)
4

These aren't 2 unicode characters... they are 4 single byte characters that also happen to be the utf-8 encodings of the unicode characters. Instead do

greek =u'ÏÎ'

Next, these are not the droids, I mean greek characters, you think they are.

>>> ord(greek[0])
207

These are codepage characters in the 128-255 range and are outside of the range you are looking for. Did you want these instead?

>>> greek = u'Ϊΐ'
>>> ord(greek[0])
938

Finally, unichr goes the wrong way... it converts ordinals to characters but you wanted to go the other way. So,

>>> for c in greek:
...     if ord(c) >= 880 and ord(c) <= 1023:
...         print(c)
... 
Ϊ
ΐ

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

python:How to print the character from a variable with unicode string

来自分类Dev

How to get the total value of to two rand() variables that match on the input value of a text form?

来自分类Dev

How to empty a numeric value from a form built with WTForm

来自分类Dev

Character display/search for Unicode characters

来自分类Dev

ORA-06502: PL/SQL: numeric or value error: character string buffer too small exception from C# code

来自分类Dev

Is it possible to get String value back from its hash code?

来自分类Dev

How to code characters in Web.Config by Unicode value

来自分类Dev

Distinguish between 'character' and 'numeric' data types in Python

来自分类Dev

input()和文字unicode解析

来自分类Dev

How to remove the first element of array without changing its key value?

来自分类Dev

How to check string for null and assign its value in the same line

来自分类Dev

Windows ASCII Character/HTML Entity/Unicode

来自分类Dev

Unicode character is changing on str_replace

来自分类Dev

How to get Google Sheets sidebar input to server

来自分类Dev

How to get input text from soft keyboard

来自分类Dev

ComboBox in metro app how to get selected text and its related id

来自分类Dev

How to get Windows-1252 character values in c++?

来自分类Dev

I want to get numeric data from string. How to do that in python?

来自分类Dev

R:比较as.character与as.integer或as.numeric

来自分类Dev

How to get a value from keyvalue pair list?

来自分类Dev

How to get the value of a node using for each and if in xpath

来自分类Dev

How to get the value from ArrayList<Object> in android

来自分类Dev

indexeddb: how to get request result and cursor value

来自分类Dev

How to get records if a column has value A, if not then B?

来自分类Dev

'Charmap' codec can't encode character (Unicode Serbian Latin)

来自分类Dev

Sort a dict by its value pairs

来自分类Dev

jQuery: how to trigger only current menu and remove style attribute if its value display : none?

来自分类Dev

How can I preserve the value of my parameters through a function so it can be used multiple times with its initial value?

来自分类Dev

ggvis input_select在scale_numeric trans参数上

Related 相关文章

  1. 1

    python:How to print the character from a variable with unicode string

  2. 2

    How to get the total value of to two rand() variables that match on the input value of a text form?

  3. 3

    How to empty a numeric value from a form built with WTForm

  4. 4

    Character display/search for Unicode characters

  5. 5

    ORA-06502: PL/SQL: numeric or value error: character string buffer too small exception from C# code

  6. 6

    Is it possible to get String value back from its hash code?

  7. 7

    How to code characters in Web.Config by Unicode value

  8. 8

    Distinguish between 'character' and 'numeric' data types in Python

  9. 9

    input()和文字unicode解析

  10. 10

    How to remove the first element of array without changing its key value?

  11. 11

    How to check string for null and assign its value in the same line

  12. 12

    Windows ASCII Character/HTML Entity/Unicode

  13. 13

    Unicode character is changing on str_replace

  14. 14

    How to get Google Sheets sidebar input to server

  15. 15

    How to get input text from soft keyboard

  16. 16

    ComboBox in metro app how to get selected text and its related id

  17. 17

    How to get Windows-1252 character values in c++?

  18. 18

    I want to get numeric data from string. How to do that in python?

  19. 19

    R:比较as.character与as.integer或as.numeric

  20. 20

    How to get a value from keyvalue pair list?

  21. 21

    How to get the value of a node using for each and if in xpath

  22. 22

    How to get the value from ArrayList<Object> in android

  23. 23

    indexeddb: how to get request result and cursor value

  24. 24

    How to get records if a column has value A, if not then B?

  25. 25

    'Charmap' codec can't encode character (Unicode Serbian Latin)

  26. 26

    Sort a dict by its value pairs

  27. 27

    jQuery: how to trigger only current menu and remove style attribute if its value display : none?

  28. 28

    How can I preserve the value of my parameters through a function so it can be used multiple times with its initial value?

  29. 29

    ggvis input_select在scale_numeric trans参数上

热门标签

归档