Giovanni Bajo wrote:
> On 09/07/2007 21.23, Walter Dörwald wrote:
>
>> >>> from ll.xist import parsers, xfind
>> >>> from ll.xist.ns import html
>> >>> e = parsers.parseURL("http://www.python.org";, tidy=True)
>> >>> print e.walknode(html.h2 & xfind.hasclass("news"))[-1]
>> Google Adds Python
On 09/07/2007 21.23, Walter Dörwald wrote:
> >>> from ll.xist import parsers, xfind
> >>> from ll.xist.ns import html
> >>> e = parsers.parseURL("http://www.python.org";, tidy=True)
> >>> print e.walknode(html.h2 & xfind.hasclass("news"))[-1]
> Google Adds Python Support to Google Calendar Dev
Raymond Hettinger wrote:
> From: "Guido van Rossum" <[EMAIL PROTECTED]>
>> But doesn't the very same argument also apply against islice(), which
>> you just offered as an alternative?
>
> Not really. The use cases for islice() typically do not involve
> repeated slices of an iterator unless it i
From: "Guido van Rossum" <[EMAIL PROTECTED]>
> But doesn't the very same argument also apply against islice(), which
> you just offered as an alternative?
Not really. The use cases for islice() typically do not involve
repeated slices of an iterator unless it is slicing off the front
few elements
Guido van Rossum wrote:
> On 7/9/07, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
>> Also, as a practical matter, I think it is a bad idea to introduce
>> __getitem__ style access to itertools because the starting point
>> moves with each consecutive access:
>>
>> # access items 0, 2, 5, 9, 14,
On 7/9/07, Raymond Hettinger <[EMAIL PROTECTED]> wrote:
> Also, as a practical matter, I think it is a bad idea to introduce
> __getitem__ style access to itertools because the starting point
> moves with each consecutive access:
>
> # access items 0, 2, 5, 9, 14, 20, ...
> for i in range(1
Raymond Hettinger wrote:
> [Walter Dörwald]
>> I'd like to propose the following addition to itertools: A function
>> itertools.getitem() which is basically equivalent to the following
>> python code:
>>
>> _default = object()
>>
>> def getitem(iterable, index, default=_default):
>>try:
>>
[Walter Dörwald]
> I'd like to propose the following addition to itertools: A function
> itertools.getitem() which is basically equivalent to the following
> python code:
>
> _default = object()
>
> def getitem(iterable, index, default=_default):
>try:
> return list(iterable)[index]
>
Guido van Rossum wrote:
> On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wrote:
> [quoting Guido]
>> > But I still want to hear of a practical use case for the default here.
>>
>> In most cases
>>
>> foo = getitem(iterable, 0, None)
>> if foo is not None:
>>...
>>
>> is simpler than
On 7/8/07, Kevin Jacobs <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> wrote:
> Also vaguely apropos:
>
> def ilen(seq):
> 'Return the length of the hopefully finite sequence'
> n = 0
> for x in seq:
> n += 1
> return n
Also known as::
sum(1 for _ in iterable)
That's always been simple
On 7/8/07, Guido van Rossum <[EMAIL PROTECTED]> wrote:
Ahem. I hope you have a better use case for getitem() than that
(regardless of the default issue). I find it clearer to write that as
try:
compid = root[ns.company_id].next()
except StopIteration:
compid = None
else:
compid = int(comp
On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wrote:
[quoting Guido]
> > But I still want to hear of a practical use case for the default here.
>
> In most cases
>
> foo = getitem(iterable, 0, None)
> if foo is not None:
>...
>
> is simpler than:
>
> try:
>foo = getitem(
Guido van Rossum wrote:
> On 7/8/07, Georg Brandl <[EMAIL PROTECTED]> wrote:
>> Guido van Rossum schrieb:
>>> How important is it to have the default in this API? __getitem__()
>>> doesn't have a default; instead, there's a separate API get() that
>>> provides a default (and I find defaulting to No
On 7/8/07, Georg Brandl <[EMAIL PROTECTED]> wrote:
> Guido van Rossum schrieb:
> > How important is it to have the default in this API? __getitem__()
> > doesn't have a default; instead, there's a separate API get() that
> > provides a default (and I find defaulting to None more manageable than
> >
Guido van Rossum schrieb:
> How important is it to have the default in this API? __getitem__()
> doesn't have a default; instead, there's a separate API get() that
> provides a default (and I find defaulting to None more manageable than
> the "_default = object()" pattern).
getattr() has a default
How important is it to have the default in this API? __getitem__()
doesn't have a default; instead, there's a separate API get() that
provides a default (and I find defaulting to None more manageable than
the "_default = object()" pattern).
--Guido
On 7/8/07, Walter Dörwald <[EMAIL PROTECTED]> wr
16 matches
Mail list logo