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


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

Re: Possible PEP Submission

Started byTerry Reedy <tjreedy@udel.edu>
First post2013-12-09 16:59 -0500
Last post2013-12-09 16:59 -0500
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: Possible PEP Submission Terry Reedy <tjreedy@udel.edu> - 2013-12-09 16:59 -0500

#61419 — Re: Possible PEP Submission

FromTerry Reedy <tjreedy@udel.edu>
Date2013-12-09 16:59 -0500
SubjectRe: Possible PEP Submission
Message-ID<mailman.3800.1386626405.18130.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web