Python unicode codepoint to unicode character

encoding, python

Solution

Python 2: Use `unichr()`:

>>> print(unichr(1081))
й

Python 3: Use `chr()`:

>>> print(chr(1081))
й

Problem

I'm trying to write out to a flat file some Chinese, or Russian or various non-English character-sets for testing purposes. I'm getting stuck on how to output a Unicode hex-decimal or decimal value to its corresponding character. For example in Python, if you had a hard coded set of characters like `абвгдежзийкл` you would assign `value = u"абвгдежзийкл"` and no problem. If however you had a single decimal or hex decimal like 1081 / 0439 stored in a variable and you wanted to print that out with it's corresponding actual character (and not just output 0x439) how would this be done? The Unicode decimal/hex value above refers to `й`.

Original source