06.12.19 04:31, Guido van Rossum пише:
(There are apparently subtle differences between re.search() and
re.findall() -- not sure if they matter in this case.)
There is no any differences.
Also, analyzing examples from GitHub, in most cases the pattern contains
no or single group, so the code
05.12.19 23:47, Kyle Stanley пише:
Serhiy Storchaka wrote:
> We still do not know a use case for findfirst. If the OP would show his
> code and several examples in others code this could be an argument for
> usefulness of this feature.
I'm not sure about the OP's exact use case, but using Gi
On Thu, Dec 5, 2019 at 22:08 Jonathan Goble wrote:
> On Fri, Dec 6, 2019, 12:47 AM Steven D'Aprano wrote:
>
>> On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote:
>> > I just found this code:
>> >
>> > def get_product_item(jsonld_items):
>> > for item in jsonld_items:
>> >
On Fri, Dec 6, 2019, 12:47 AM Steven D'Aprano wrote:
> On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote:
> > I just found this code:
> >
> > def get_product_item(jsonld_items):
> > for item in jsonld_items:
> > if item['@type'] == 'Product':
> > return item
>
On Thu, Dec 05, 2019 at 05:40:05PM -0400, Juancarlo Añez wrote:
> I just found this code:
>
> def get_product_item(jsonld_items):
> for item in jsonld_items:
> if item['@type'] == 'Product':
> return item
> else:
> return {}
I'm sorry, I can't tell what that is
On Thu, Dec 5, 2019 at 6:16 PM Juancarlo Añez wrote:
> It’s unfortunate that these functions aren’t better matched. Why is there
>> a simple-semantics find-everything and a match-semantics find-iteratively
>> and find-one? But I don’t think adding a simple-semantics find-one that
>> works by inef
>
> It’s unfortunate that these functions aren’t better matched. Why is there
> a simple-semantics find-everything and a match-semantics find-iteratively
> and find-one? But I don’t think adding a simple-semantics find-one that
> works by inefficiently finding all is the right solution.
>
The prop
To overcome Github's search limitations, one can use Chrome's codesearch or
the public github dataset available on bigquery (note: it's only a sample
from 2012 if I'm not mistaken).
https://cs.chromium.org/search/?q=lang:py+re%5C.findall%5C(.*%5C)%5C%5B0%5C%5D&sq=package:chromium&type=cs
returns
5
On 12/05/2019 03:11 PM, Josh Rosenberg wrote:
"Also, the for-loop version quits the moment it finds a Product type, while the
`first` version has to first process the entire jsonld_items structure."
The first version doesn't have to process the whole structure; it's written
with a generator e
"Also, the for-loop version quits the moment it finds a Product type, while
the `first` version has to first process the entire jsonld_items structure."
The first version doesn't have to process the whole structure; it's written
with a generator expression, so it only tests and produces values on
I have encountered plenty of uses for first(), usually the argument is a
list or even a dict or set that’s already computed — for sets, it’s common
that it’s known there’s only one element, the question is how to get that
element.
On Thu, Dec 5, 2019 at 14:28 Andrew Barnert via Python-ideas <
pyth
On Dec 5, 2019, at 13:43, Juancarlo Añez wrote:
>
>
> I just found this code:
>
> def get_product_item(jsonld_items):
> for item in jsonld_items:
> if item['@type'] == 'Product':
> return item
> else:
> return {}
>
> My argument is that the intent is cleare
On 12/05/2019 01:40 PM, Juancarlo Añez wrote:
I just found this code:
def get_product_item(jsonld_items):
for item in jsonld_items:
if item['@type'] == 'Product':
return item
else:
return {}
My argument is that the intent is cle
Serhiy Storchaka wrote:
> We still do not know a use case for findfirst. If the OP would show his
> code and several examples in others code this could be an argument for
> usefulness of this feature.
I'm not sure about the OP's exact use case, but using GitHub's code search
for .py files that mat
I just found this code:
def get_product_item(jsonld_items):
for item in jsonld_items:
if item['@type'] == 'Product':
return item
else:
return {}
My argument is that the intent is clearer in:
def get_product_item(jsonld_items):
return first((item for item
Thanks for pointing those out.
At least when the alias is `error = OtherName` the text is the stack trace are
informative.
--
M
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
ht
05.12.19 21:25, Matthias Bussonnier пише:
I've been tripped up a couple of time by a few Exception names being lower case
both in code and tracebacks. In particular `error` (all lower case)
I tend to read `error` as a function instead of a class.
According to my non-scientific grep-foo, I find
05.12.19 21:07, Guido van Rossum пише:
The case for findfirst() becomes stronger! There seem plenty of ways to
get this wrong.
I write several functions every day. There are many ways to get this
wrong. But I do not propose to include all these functions in the
stdlib. If I want to include ev
I've been tripped up a couple of time by a few Exception names being lower case
both in code and tracebacks. In particular `error` (all lower case)
I tend to read `error` as a function instead of a class.
According to my non-scientific grep-foo, I find that ~ 300 descendant from
Exceptions st
The case for findfirst() becomes stronger! There seem plenty of ways to get
this wrong.
On Thu, Dec 5, 2019 at 09:30 Andrew Barnert via Python-ideas <
python-ideas@python.org> wrote:
> On Dec 5, 2019, at 08:53, Juancarlo Añez wrote:
>
>
>
> The proposed implementation of a findfirst() would hand
On Wed, Dec 4, 2019 at 3:12 PM Guido van Rossum wrote:
> We could treat it as a kind of future statement. If there’s a top level
> statement that defines the magic identitier we generate the special
> bytecode.
>
True, that would help solve the performance issue.
But I'm still -1 on the idea re
On Dec 5, 2019, at 08:53, Juancarlo Añez wrote:
>
>
> The proposed implementation of a findfirst() would handle many common cases,
> and be friendly to newcomers (why do I need to deal with a Match object?),
> specially if the semantics are those of findall():
>
> next(iter(findall(...))
On Dec 5, 2019, at 08:53, Juancarlo Añez wrote:
>
> BTW, a common function in extensions to itertools is first():
>
> def first(seq, default=None):
> return next(iter(seq), default= default)
>
> That function, first(), would also be a nice addition in itertools, and
> findfirst() c
On Wed, Dec 4, 2019 at 3:02 PM Guido van Rossum wrote:
> Fair enough. I’ll let the OP defend his use case.
>
The OP thinks that the case for wanting just the string for a first regex
match, or a verifiable default if there is no match, is way too common,
that the advice on the web is not very go
My little experiments in 3.7 show exception setup is about 40% more costly
than just a do-nothing loop, but execution of is about 9x more expensive
than doing nothing, so actually very little cost if your loop only rarely
catches the exception (I assume you'll probably actually do something
inside
25 matches
Mail list logo