Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get unicode code point of a character using Python

In Python API, is there a way to extract the unicode code point of a single character?

Edit: In case it matters, I'm using Python 2.7.

like image 729
SK9 Avatar asked Sep 03 '11 04:09

SK9


2 Answers

If I understand your question correctly, you can do this.

>>> s='㈲' >>> s.encode("unicode_escape") b'\\u3232' 

Shows the unicode escape code as a source string.

like image 111
Keith Avatar answered Sep 28 '22 12:09

Keith


>>> ord(u"ć") 263 >>> u"café"[2] u'f' >>> u"café"[3] u'\xe9' >>> for c in u"café": ...     print repr(c), ord(c) ...  u'c' 99 u'a' 97 u'f' 102 u'\xe9' 233 
like image 39
Mike Graham Avatar answered Sep 28 '22 11:09

Mike Graham