Reputation: 168
# python2
print(chr(174))
?
# python3
print(chr(174))
®
I'm looking for the equivalent of chr() from python2. I believe this is due to python 3 returning unicode characters rather than ASCII.
Upvotes: 6
Views: 5010
Reputation: 5789
Actually, in Py3 chr
is equivalent of unichr
in Py2. You can use bytes
or bytearray
.
For example:
>>> print(bytes([174]))
b'\xae'
or
>>> print(bytearray([174]))
bytearray(b'\xae')
b'\xae' equals to ?
Upvotes: 6
Reputation: 96246
I believe that this would be the closest equivalent:
>>> print(chr(174).encode('ascii', errors='replace'))
b'?'
>>>
Upvotes: 2