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


Groups > comp.lang.python > #38434

Re: Curious to see alternate approach on a search/replace via regex

From Peter Otten <__peter__@web.de>
Subject Re: Curious to see alternate approach on a search/replace via regex
Date 2013-02-08 10:22 +0100
Organization None
References <20130206134105.9352d665e1f8d0719021fcf9@lavabit.com> <kevta5$ii3$1@ger.gmane.org> <kf0mbg$bd1$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.1494.1360315337.2939.python-list@python.org> (permalink)

Show all headers | View raw


Serhiy Storchaka wrote:

> On 07.02.13 11:49, Peter Otten wrote:
>> ILLEGAL = "-:./?&="
>> try:
>>      TRANS = string.maketrans(ILLEGAL, "_" * len(ILLEGAL))
>> except AttributeError:
>>      # python 3
>>      TRANS = dict.fromkeys(map(ord, ILLEGAL), "_")
> 
> str.maketrans()

D'oh.

ILLEGAL = "-:./?&="
try:
    maketrans = str.maketrans
except AttributeError:
    # python 2
    from string import maketrans
TRANS = maketrans(ILLEGAL, "_" * len(ILLEGAL))
...

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


Thread

Re: Curious to see alternate approach on a search/replace via regex Peter Otten <__peter__@web.de> - 2013-02-08 10:22 +0100

csiph-web