我是Python新手.
为什么this在Python 3.1中不起作用?
from string import maketrans # Required to call maketrans function.
intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)
str = "this is string example....wow!!!";
print str.translate(trantab);
当我执行上述代码时,我得到了以下结果:
Traceback (most recent call last):
File "<pyshell#119>", line 1, in <module>
transtab = maketrans(intab, outtab)
File "/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/string.py", line 60, in maketrans
raise TypeError("maketrans arguments must be bytes objects")
TypeError: maketrans arguments must be bytes objects
"必须是字节对象"是什么意思?如果可能的话,有人能帮我发布一个Python3.1的工作代码吗?