我是一个Python新手.
为什么这在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);
Run Code Online (Sandbox Code Playgroud)
当我执行上面的代码时,我得到以下代码:
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
Run Code Online (Sandbox Code Playgroud)
"必须是字节对象"是什么意思?如果有可能,有人可以帮助发布Python 3.1的工作代码吗?