Python Forum
Python 2 Unicode question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python 2 Unicode question (/thread-12693.html)



Python 2 Unicode question - Skaperen - Sep-08-2018

when using the Unicode type in Python 2, what are the ord() and chr() like functions to convert to the numeric values of the characters and back? ok, ord() works but chr() is limited to values less than 256. or do i need to do this:
def uchr(u):
    return eval("u'\\u"+hex(u+2**24)[-max(len(hex(u))-2,4):]+"'")



RE: Python 2 Unicode question - Gribouillis - Sep-08-2018

Doesn't builtin unichr() fit your needs?


RE: Python 2 Unicode question - Skaperen - Sep-08-2018

i'll try that one. i only have Python 3 docs handy, so i was guessing the names. i should have looked at sit(__builtins__).