说ord(some_buffer [n])的可移植方式是什么?

时间:2015-10-02 20:00:58

标签: python-2.7 python-3.x

> python2 -c "print(ord(b'a'[0]))" 
97
> python3 -c "print(ord(b'a'[0]))"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: ord() expected string of length 1, but int found

如何以适用于Python 2和Python 3的方式编写此代码?

0 个答案:

没有答案