Hat*_*sut 5 python unicode repr python-2.7 python-3.x
在Python 3和Python 2中,__repr__应该返回字节还是unicode?参考和报价是理想的.
类型是str(对于python2.x和python3.x):
>>> type(repr(object()))
<class 'str'>
Run Code Online (Sandbox Code Playgroud)
必须是这种情况,因为如果前者不存在则__str__默认调用__repr__,但__str__ 必须返回a str.
对于那些不知道的人,在python3.x中,str是表示unicode的类型.在python2.x中,str是表示字节的类型.