Python Forum

Full Version: Python 2 Unicode question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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):]+"'")
Doesn't builtin unichr() fit your needs?
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__).