[perl-python] unicode study with unicodedata module

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

python has this nice unicodedata module that deals with unicode nicely.

#-*- coding: utf-8 -*-
# python

from unicodedata import *

# each unicode char has a unique name.
# one can use the “lookup” func to find it

mychar=lookup('greek cApital letter sIgma')
# note letter case doesn't matter
print mychar.encode('utf-8')

m=lookup('CJK UNIFIED IDEOGRAPH-5929')
# for some reason, case must be right here.
print m.encode('utf-8')

# to find a char's name, use the “name” function
print name(u'天')

basically, in unicode, each char has a number of attributes (called
properties) besides its name. These attributes provides necessary info
to form letters, words, or processing such as sorting, capitalization,
etc, of varous human scripts. For example, Latin alphabets has two
forms of upper case and lower case. Korean alphabets are stacked
together. While many symbols corresponds to numbers, and there are also

combining forms used for example to put a bar over any letter or
character. Also some writings systems are directional. In order to form

these symbols for display or process them for computing, info of these
on each char is necessary.

the rest of functions in unicodedata return these attributes.

see unicodedata doc:

Official word on unicode character properties:

i don't know what's the state of Perl's unicode. Is there something

this post is archived at


Re: [perl-python] unicode study with unicodedata module

Xah Lee wrote:

> i don't know what's the state of Perl's unicode.

perldoc perlunicode

Re: unicode study with unicodedata module

here's a snippet of code that prints a range of unicode chars, along
with their ordinal in hex, and name.

chars without a name are skipped. (some of such are undefined code

On Microsoft Windows the encoding might need to be changed to utf-16.

Change the range to see different unicode chars.

# -*- coding: utf-8 -*-

from unicodedata import *

for i in range(0x0000, 0x0fff):
    l.append(eval('u"\u%04x"' % i))

for x in l:
    if name(x,'-')!='-':
        print x.encode('utf-8'),'|', "%04x"%(ord(x)), '|', name(x,'-')

anyone wants to supply a Perl version?


Brian McCauley wrote:
> Xah Lee wrote:
> > i don't know what's the state of Perl's unicode.
> perldoc perlunicode

Re: [perl-python] unicode study with unicodedata module

Fuck google incorporated for editing my subject name without

and fuck google incorporated  for editing my message content without



Site Timeline