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


Groups > comp.lang.python > #61419

Re: Possible PEP Submission

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Possible PEP Submission
Date 2013-12-09 16:59 -0500
References <CAJ=TTfA3qpYtw-ix-MU_0tOy5jxYanTjJoEURGiau=sUiYL1XQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3800.1386626405.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 12/9/2013 3:36 PM, Logan Collins wrote:
> Just checking whether 1) a PEP is the proper place for this

No, not needed. If, after discussion here (or python-ideas), such a 
change would only need a tracker issue.

> and 2) what y'all think about it.

> I would like to propose a change to the the 're' standard library to
> support iterables.

Not really. You are proposing that re.sub accept an iterable of strings 
for the replacement string.

> So, something like the following would work:
>
> import re
> text = """hello user
> hello user
> hello user"""

Repeating the text is the wrong approach. So is using re when not needed.

> users = ["Bob", "Alice", "Jeffery"]
>
> newtext = re.sub("user", users, text)
>
> # newtext = "hello Bob\nhello Alice\nhello Jeffery"

 >>> '\n'.join('Hello user'.replace('user', name) for name in ["Bob", 
"Alice", "Jeffery"])

'Hello Bob\nHello Alice\nHello Jeffery'

-- 
Terry Jan Reedy

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


Thread

Re: Possible PEP Submission Terry Reedy <tjreedy@udel.edu> - 2013-12-09 16:59 -0500

csiph-web