Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43384
| References | <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> |
|---|---|
| Date | 2013-04-12 01:45 +1000 |
| Subject | Re: My string module doesn't have maketrans or translate functions |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.484.1365695113.3114.python-list@python.org> (permalink) |
On Fri, Apr 12, 2013 at 1:30 AM, Lamb <lambandme@gmail.com> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
My string module doesn't have maketrans or translate functions Lamb <lambandme@gmail.com> - 2013-04-11 08:30 -0700
Re: My string module doesn't have maketrans or translate functions Chris Angelico <rosuav@gmail.com> - 2013-04-12 01:45 +1000
Re: My string module doesn't have maketrans or translate functions Lamb <lambandme@gmail.com> - 2013-04-11 09:05 -0700
Re: My string module doesn't have maketrans or translate functions Chris Angelico <rosuav@gmail.com> - 2013-04-12 02:09 +1000
Re: My string module doesn't have maketrans or translate functions Lamb <lambandme@gmail.com> - 2013-04-11 09:05 -0700
Re: My string module doesn't have maketrans or translate functions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-04-11 17:56 +0100
Re: My string module doesn't have maketrans or translate functions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-12 00:17 +0000
csiph-web