Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!tudelft.nl!txtfeed1.tudelft.nl!newsfeed10.multikabel.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.051 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; '>>>>': 0.09; 'subject:string': 0.09; 'received:209.85.214.174': 0.13; '[1].': 0.16; 'subject:unicode': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'subject:skip:s 10': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'documented': 0.23; 'cc:2**0': 0.24; 'thanks.': 0.26; 'message-id:@mail.gmail.com': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'subject:number': 0.30; 'url:library': 0.31; "i've": 0.31; 'received:209.85.214': 0.32; 'url:python': 0.36; '...': 0.36; 'received:google.com': 0.37; 'think': 0.37; 'received:209.85': 0.38; 'url:docs': 0.39; 'url:org': 0.39; "it's": 0.40; 'received:209': 0.40; '2011': 0.61; 'spot': 0.79; 'blind': 0.84; 'otten': 0.84; 'why:': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=40OmeA+JjUEmkLw9ZhYolCZ+laC6/MvEmLAp75wUjHw=; b=TJSekvcdHgc2pl5HvVhqLnK946zuxOdscTvQ6tN/QuWMJzb2WNA0jOQst0x/PHGjGK +EAbk1pR3i6fADEy/eidIV01xNCAsJtJw44TFeu/Vn9K8/5f+yx7bDcCnj4lYbEWp7dh BJD7bAtjAZeSlVkaY9FuqYyHUmhM9qwKvDXXo= MIME-Version: 1.0 In-Reply-To: References: Date: Tue, 20 Dec 2011 17:04:48 +0000 Subject: Re: Performing a number of substitutions on a unicode string From: Arnaud Delobelle To: Peter Otten <__peter__@web.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 21 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324400691 news.xs4all.nl 6846 [2001:888:2000:d::a6]:60117 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17589 On 20 December 2011 15:35, Peter Otten <__peter__@web.de> wrote: >>>> escape_map =3D { > ... =C2=A0 =C2=A0 u'\n': u'\\n', > ... =C2=A0 =C2=A0 u'\t': u'\\t', > ... =C2=A0 =C2=A0 u'\r': u'\\r', > ... =C2=A0 =C2=A0 u'\f': u'\\f', > ... =C2=A0 =C2=A0 u'\\': u'\\\\' > ... } >>>> escape_map =3D dict((ord(k), v) for k, v in escape_map.items()) >>>> print u"the quick\n brown\tfox > jumps\\over\\the\\lazy\\dog".translate(escape_map) > the quick\n brown\tfox jumps\\over\\the\\lazy\\dog Thanks. I think I've got a blind spot about unicode.translate. Actually, I know why: it's not properly documented where I look [1]. --=20 Arnaud [1] http://docs.python.org/library/stdtypes.html#str.translate