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


Groups > comp.lang.python > #43384

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

Path csiph.com!usenet.pasdenom.info!news.albasani.net!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.034
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'string': 0.09; 'subject:module': 0.09; 'subject:string': 0.09; 'python': 0.11; 'changes': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'instead:': 0.16; 'wrote:': 0.18; 'import': 0.22; 'unicode': 0.24; 'handling': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'changed.': 0.31; 'fri,': 0.33; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'received:209': 0.37; 'to:addr :python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'details.': 0.61; 'more': 0.64; 'due': 0.66; 'subject:have': 0.80; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=6WOIuiiW/+odiEPgay2x6+lrMaQjAdGpRf7IW1qXxfU=; b=DHvyHr2cW49No75iy5Eurn4SESbU27xZFG6sBkvjjKtsSYZPGWO/4fehzijNHX7wcI y5CKLinVVWXELqKR3vv6PH/8CpSrhHB/+zLbaRWGFbwtHnpLne1IOmgU9hrvx53yw3Ir IUeo9OYH7Mlgv/h3KozsSRat/eE+AWItfxlFHAgi3+/W7hlesPYwIFrz1Hd77UL5qFV4 BJC9v/dONoLbz25N2NMIOJRHH2xbacHzdyVqT8Glm6xUQJD35XRpD47WCGJlPkV+LXUn Wq9s/zJe21gFG+3FHW5pr3CuF2pb/b6OQQwwrvzREgkqxUbz95fHG3Q9jikAAoIzcvmJ rtyg==
MIME-Version 1.0
X-Received by 10.220.223.80 with SMTP id ij16mr5510301vcb.28.1365695105465; Thu, 11 Apr 2013 08:45:05 -0700 (PDT)
In-Reply-To <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com>
References <338cca79-08c6-4c6f-89a4-d3a50ece3dee@googlegroups.com>
Date Fri, 12 Apr 2013 01:45:05 +1000
Subject Re: My string module doesn't have maketrans or translate functions
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.484.1365695113.3114.python-list@python.org> (permalink)
Lines 17
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365695113 news.xs4all.nl 2661 [2001:888:2000:d::a6]:49865
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43384

Show key headers only | View raw


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 | 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