My string module doesn't have maketrans or translate functions

Lamb lambandme at gmail.com
Thu Apr 11 11:30:27 EDT 2013


Hi all,
 I'm really new to python and trying to figure out the basic rule and settings of it. I'm using python 3.3 and I was trying this code in python:

import string
s = "string. With. Punctuation?" 
out = s.translate(string.maketrans("",""), string.punctuation)

And I got the following error:
Traceback (most recent call last):
  File "C:/Python33/trials/ls.py", line 5, in <module>
    out = s.translate(string.maketrans("",""), string.punctuation)
AttributeError: 'module' object has no attribute 'maketrans'

So I used the following to see functions inside string
e=dir(string)
>>> print(e)
['ChainMap', 'Formatter', 'Template', '_TemplateMetaclass', '__builtins__', '__cached__', '__doc__', '__file__', '__initializing__', '__loader__', '__name__', '__package__', '_re', '_string', 'ascii_letters', 'ascii_lowercase', 'ascii_uppercase', 'capwords', 'digits', 'hexdigits', 'octdigits', 'printable', 'punctuation', 'whitespace']

It doesn't have translate(), maketrans(), rstrip() and a whole lot of other things. What's the problem?

Thanks!



More information about the Python-list mailing list