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


Groups > comp.lang.python > #38434 > unrolled thread

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

Started byPeter Otten <__peter__@web.de>
First post2013-02-08 10:22 +0100
Last post2013-02-08 10:22 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

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

FromPeter Otten <__peter__@web.de>
Date2013-02-08 10:22 +0100
SubjectRe: Curious to see alternate approach on a search/replace via regex
Message-ID<mailman.1494.1360315337.2939.python-list@python.org>
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))
...

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web