Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43386

Re: My string module doesn't have maketrans or translate functions

Newsgroups comp.lang.python
Date 2013-04-11 09:05 -0700
References <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> <mailman.484.1365695113.3114.python-list@python.org>
Subject Re: My string module doesn't have maketrans or translate functions
From Lamb <lambandme@gmail.com>
Message-ID <mailman.485.1365696329.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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