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


Groups > comp.lang.python > #61416

Re: Possible PEP Submission

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'matches': 0.07; 'modified': 0.07; 'subject:PEP': 0.07; 'users,': 0.07; 'pep': 0.09; 'python:': 0.09; 'wrapped': 0.09; '"hello': 0.16; '-tkc': 0.16; 'collins': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'lambda': 0.16; 'think?': 0.16; 'wrote:': 0.18; 'library': 0.18; 'import': 0.22; 'print': 0.22; 'case.': 0.24; 'propose': 0.24; 'certain': 0.27; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'work:': 0.31; 'class': 0.32; 'text': 0.33; 'cases': 0.33; 'checking': 0.33; 'entirely': 0.33; 'could': 0.34; 'something': 0.35; 'case,': 0.35; 'but': 0.35; 'there': 0.35; 'library.': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'so,': 0.37; 'handle': 0.38; 'to:addr:python-list': 0.38; 'stock': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'users': 0.40; 'even': 0.60; 'new': 0.61; 'worth': 0.66; 'clearer': 0.84; 'received:50.22': 0.84; 'subject:Possible': 0.84
Date Mon, 9 Dec 2013 15:01:22 -0600
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Possible PEP Submission
In-Reply-To <CAJ=TTfA3qpYtw-ix-MU_0tOy5jxYanTjJoEURGiau=sUiYL1XQ@mail.gmail.com>
References <CAJ=TTfA3qpYtw-ix-MU_0tOy5jxYanTjJoEURGiau=sUiYL1XQ@mail.gmail.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3798.1386622813.18130.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386622813 news.xs4all.nl 2868 [2001:888:2000:d::a6]:36420
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61416

Show key headers only | View raw


On 2013-12-09 14:36, Logan Collins wrote:
> Just checking whether 1) a PEP is the proper place for this and 2)
> what y'all think about it.
> 
> I would like to propose a change to the the 're' standard library to
> support iterables.
> 
> So, something like the following would work:
> 
> import re
> text = """hello user
> hello user
> hello user"""
> 
> users = ["Bob", "Alice", "Jeffery"]
> 
> newtext = re.sub("user", users, text)
> 
> # newtext = "hello Bob\nhello Alice\nhello Jeffery"
> 
> There are a few corner cases I'm not sure what would be the best
> behavior. Nor am I entirely certain this should be modified
> functionality or just... a new function. What do y'all think?

Well, it's not that hard to do in stock python:

  i = itertools.cycle(users)
  print re.sub(
    'user',
    lambda m: next(i),
    text
    )

which should handle both the "fewer matches than items in users"
case, as well as wrap around in the "more matches than items in
users" case.  If you don't want wrap-around, just use iter(users)
instead of itertools.cycle(users)

This could be wrapped up in some class to give it a clearer name, but
I'm not sure it's worth doing a PEP or even including it in the
standard library.

-tkc



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


Thread

Re: Possible PEP Submission Tim Chase <python.list@tim.thechases.com> - 2013-12-09 15:01 -0600

csiph-web