How come string.maketrans does not work in Python 3.1?
        Posted  
        
            by ShaChris23
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ShaChris23
        
        
        
        Published on 2010-06-13T04:15:42Z
        Indexed on 
            2010/06/13
            4:22 UTC
        
        
        Read the original article
        Hit count: 464
        
python
|python-3.1
I'm a Python newbie.
How come this doesn't work in 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);
When I executed the above code, I get the following instead:
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
What does "must be bytes objects" mean? Could anyone please help post a working code for Python 3.1 if it's possible?
© Stack Overflow or respective owner