Possible PEP Submission

Terry Reedy tjreedy at udel.edu
Mon Dec 9 22:59:48 CET 2013


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




More information about the Python-list mailing list