On 16/06/2012 00:42, Jason Friedman wrote:
This is a related question.

I perform an octal dump on a file:
$ od -cx file
0000000   h   e   l   l   o       w   o   r   l   d  \n
            6568    6c6c    206f    6f77    6c72    0a64

I want to output the names of those characters:
$ python3
Python 3.2.3 (default, May 19 2012, 17:01:30)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 import unicodedata
 unicodedata.name("\u0068")
'LATIN SMALL LETTER H'
 unicodedata.name("\u0065")
'LATIN SMALL LETTER E'

But, how to do this programatically:
 first_two_letters = "6568    6c6c    206f    6f77    6c72    0a64".split()[0]
 first_two_letters
'6568'
 first_letter = "00" + first_two_letters[2:]
 first_letter
'0068'

Now what?

>>> hex_code = "65"
>>> unicodedata.name(chr(int(hex_code, 16)))
'LATIN SMALL LETTER E'
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to