Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I print all unicode characters?

Tags:

python

I want to print some unicode characters but u'\u1000' up to u'\u1099'. This doesn't work:

for i in range(1000,1100):
    s=unicode('u'+str(i))
    print i,s
like image 556
Dirk Nachbar Avatar asked Oct 31 '11 21:10

Dirk Nachbar


People also ask

How do I print Unicode?

Use the "\u" escape sequence to print Unicode characters In a string, place "\u" before four hexadecimal digits that represent a Unicode code point.

How do I type all Unicode characters?

Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X. For more Unicode character codes, see Unicode character code charts by script.

Which function is used to print the Unicode value of a character?

The following example uses the UNICODE and NCHAR functions to print the UNICODE value of the first character of the string Åkergatan 24 , and to print the actual first character, Å . DECLARE @nstring NCHAR(12); SET @nstring = N'Åkergatan 24'; SELECT UNICODE(@nstring), NCHAR(UNICODE(@nstring));

How do I show Unicode in Python?

To include Unicode characters in your Python source code, you can use Unicode escape characters in the form \u0123 in your string. In Python 2. x, you also need to prefix the string literal with 'u'.


2 Answers

You'll want to use the unichr() builtin function:

for i in range(1000,1100):
    print i, unichr(i)

Note that in Python 3, just chr() will suffice.

like image 77
Sanqui Avatar answered Sep 25 '22 06:09

Sanqui


Use unichr:

s = unichr(i)

From the documentation:

unichr(i)

Return the Unicode string of one character whose Unicode code is the integer i. For example, unichr(97) returns the string u'a'.

like image 42
Mark Byers Avatar answered Sep 22 '22 06:09

Mark Byers