My string module doesn't have maketrans or translate functions
Lamb
lambandme at gmail.com
Thu Apr 11 12:05:18 EDT 2013
Thanks! It worked! But why didn't I see functions : translate(), maketrans(), rstrip(), etc. listed when I called print(dir(string))?
On Thursday, April 11, 2013 11:45:05 AM UTC-4, Chris Angelico wrote:
>
> > import string
>
> > s = "string. With. Punctuation?"
>
> > out = s.translate(string.maketrans("",""), string.punctuation)
>
>
>
> Try this instead:
>
>
>
> import string
>
> s = "string. With. Punctuation?"
>
> out = s.translate(str.maketrans("", "", string.punctuation))
>
>
>
> Due to the changes in string handling (s is a Unicode string in Python
>
> 3, not a string of bytes), str.translate() got changed. Check out
>
> help(str.maketrans) and help(str.translate) in interactive Python for
>
> more details.
>
>
>
> ChrisA
More information about the Python-list
mailing list