[英]Equivalent of python2 chr(int) in python3
# python2
print(chr(174))
?
# python3
print(chr(174))
®
I'm looking for the equivalent of chr() from python2. 我正在寻找python2中相当于chr()的东西。 I believe this is due to python 3 returning unicode characters rather than ASCII.
我相信这是由于python 3返回unicode字符而不是ASCII。
I believe that this would be the closest equivalent: 我相信这将是最接近的等价物:
>>> print(chr(174).encode('ascii', errors='replace'))
b'?'
>>>
Actually, in Py3 chr
is equivalent of unichr
in Py2. 实际上,在Py3中,
chr
相当于Py2中的unichr
。 You can use bytes
or bytearray
. 您可以使用
bytes
或bytearray
。
For example: 例如:
>>> print(bytes([174]))
b'\xae'
or 要么
>>> print(bytearray([174]))
bytearray(b'\xae')
b'\\xae' equals to ? b'\\ xae'等于?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.