Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.osn.de!diablo2.news.osn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'subject:PEP': 0.07; 'users,': 0.07; 'if,': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'jan': 0.12; '"hello': 0.16; 'collins': 0.16; 'iterable': 0.16; 'name)': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'library': 0.18; '>>>': 0.22; 'import': 0.22; 'issue.': 0.22; 'header:User- Agent:1': 0.23; 'propose': 0.24; '(or': 0.24; 'tracker': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'needed.': 0.30; "skip:' 10": 0.31; 'proposing': 0.31; 'work:': 0.31; 'text': 0.33; 'checking': 0.33; 'skip:u 20': 0.35; 'something': 0.35; 'no,': 0.35; 'wrong': 0.37; 'so,': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'users': 0.40; 'received:173': 0.61; 'name': 0.63; 'such': 0.63; 'here': 0.66; 'received:fios.verizon.net': 0.84; 'subject:Possible': 0.84; 'approach.': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: Possible PEP Submission Date: Mon, 09 Dec 2013 16:59:48 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-254-207.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386626405 news.xs4all.nl 2871 [2001:888:2000:d::a6]:50387 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61419 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