Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43391
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: My string module doesn't have maketrans or translate functions |
| Date | 2013-04-11 17:56 +0100 |
| References | <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.488.1365699359.3114.python-list@python.org> (permalink) |
On 11/04/2013 16:30, Lamb wrote:
> 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!
>
The string module is effectively dead. Many functions were deprecated
back in 2.6, maketrans in 3.1, just use string methods instead.
--
If you're using GoogleCrap™ please read this
http://wiki.python.org/moin/GoogleGroupsPython.
Mark Lawrence
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