Python - unichr() - 'charmap' codec can't encode character
Question: I would like to ask you for help. I have to decode unicode decimal to chars,
but I am not decoding only clasisc letters, I am decoding special characters
like: ؋,лв and some more ¥ and it doesn't work - it says : 'charmap' codec
can't encode character. Can you help me?

I have to work with all symbols of currency from this page:
<http://www.xe.com/symbols.php>, thank you.

Edit: For example I need to get from decimal number 1547 symbol "؋".


Answer: It helps to provide an example like the following. This makes it clear about
the operating environment (OS and Python version):

    
    
    Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> print(unichr(1547))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python27\encodings\cp437.py", line 12, in encode
        return codecs.charmap_encode(input,errors,encoding_map)
    UnicodeEncodeError: 'charmap' codec can't encode character u'\u060b' in position 0: character maps to <undefined>
    

The problem is not with conversion, but with printing. In the above case, the
Windows console is using `cp437` encoding, and that doesn't support the
character being printed.

The conversion works correctly, `c` contains a Unicode character, and it is
the `AFGHANI SIGN`.

    
    
    >>> c = unichr(1547)
    >>> c
    u'\u060b'
    >>> import unicodedata as ud
    >>> ud.name(c)
    'AFGHANI SIGN'
    

If you want it to print correctly, one way is to use an IDE `PythonWin` from
the `pywin32` extensions that supports UTF-8 encoded output:

    
    
    PythonWin 2.7.11 (v2.7.11:6d1b6a68f775, Dec  5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32.
    Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
    >>> unichr(1547)
    u'\u060b'
    >>> print(unichr(1547))
    ؋
    

Another is to write the output to a UTF-8-encoded file, and open the result in
Notepad:

    
    
    with io.open('out.txt','w',encoding='utf8') as f:
        f.write(unichr(1547)+unichr(402)+unichr(165))
    

Output file:

    
    
    ؋ƒ¥
    

