How can I duplicate python 2 chr exactly in python 3
Question: Hi I am trying to migrate some code to python 3 but am having the following
problem.

Python 2

    
    
    >>> a = chr(217)
    >>> print a, type(a)
    � <type 'str'>
    

Python 3

    
    
    >>> a = chr(217)
    >>> print(a, type(a))
    Ù <class 'str'>
    

The reason is that I have Existing data created with the following code

    
    
    from Crypto.Cipher import AES
    
    fle = open("data.dat", "wt")
    key = "password000*****"
    pwd = AES.new(key, AES.MODE_ECB)
    for dat in ("dataname001*****", "dataname002*****"):
        txt = ""
        hsh = pwd.encrypt(dat)
        for c in hsh:
            txt = txt + str(ord(c)) + ","
        fle.write("%s\n" % txt[:-1])
    fle.close()
    

I need to read the data which I can do using python2 but not python3

    
    
    fle = open("data.dat", "rt")
    for dat in fle:
        txt = ""
        for c in dat.split(","):
            txt = txt + chr(int(c))
        print(pwd.decrypt(txt))
    


Answer: [`chr` in Python3.x](https://docs.python.org/3/library/functions.html#chr) is
similar to [`unichr` in Python
2.x](https://docs.python.org/2/library/functions.html#unichr).

If you want a byte string, use
[`bytes`](https://docs.python.org/3/library/functions.html#bytes):

    
    
    >>> bytes([217])
    b'\xd9'
    

or [`bytearray`](https://docs.python.org/3/library/functions.html#bytearray):

    
    
    >>> bytearray([217])
    bytearray(b'\xd9')
    

