Duncan Booth wrote:
> Armin wrote:
>
> > Could you give an example of next() with a sentinel and describe its
> > use case please? I have a little trouble understanding what you guys
> > mean!
>
> It means you don't have to worry about next() throwing StopIteration.
>
> e.g.
> >>> def pairs
Armin writes:
>> Yep, that's what I meant, I forgot the parameter name.
>
> Could you give an example of next() with a sentinel and describe its
> use case please? I have a little trouble understanding what you
> guys mean!
See the thread about reading the file in chunks. Instead of:
while Tr
Armin wrote:
> Could you give an example of next() with a sentinel and describe its
> use case please? I have a little trouble understanding what you guys
> mean!
It means you don't have to worry about next() throwing StopIteration.
e.g.
>>> def pairs(sequence, padding=None):
sequenc
On Tuesday 17 March 2009 19:04:25 Luis Zarrabeitia wrote:
> On Tuesday 17 March 2009 03:17:02 pm R. David Murray wrote:
> > > > (btw, I love the new sentinel argument for the next function in
> > > > python3!)
> > >
> > > next() doesn't have a sentinel argument. It's iter() which does, and
> > > th
On Tuesday 17 March 2009 03:17:02 pm R. David Murray wrote:
> > > (btw, I love the new sentinel argument for the next function in
> > > python3!)
> >
> > next() doesn't have a sentinel argument. It's iter() which does, and
> > that's in 2.x also.
>
> But it does have a 'default' argument, and you c
Benjamin Peterson wrote:
> Luis Zarrabeitia uh.cu> schrieb:
> >
> > Works for python2.4 and 2.5 also.
> >
> > In python3, this should be used instead:
> >
> > >>> b = iter(a)
> > >>> c = next(b)
> >
> > (btw, I love the new sentinel argument for the next function in python3!)
>
> next() does
Luis Zarrabeitia uh.cu> schrieb:
>
> Works for python2.4 and 2.5 also.
>
> In python3, this should be used instead:
>
> >>> b = iter(a)
> >>> c = next(b)
>
> (btw, I love the new sentinel argument for the next function in python3!)
next() doesn't have a sentinel argument. It's iter() which do
Quoting andrew cooke :
> Andre Engels wrote:
> [...]
> b = a.__iter__()
>
> not sure from what version, but certainly in 2.6 and on, you can improve
> the syntax slightly:
> >>> b = iter(a)
> >>> b.next()
Indeed. Directly calling __special_methods__ should be avoided. That one is a
better i
not sure from what version, but certainly in 2.6 and on, you can improve
the syntax slightly:
b = iter(a)
b.next()
This syntax (also my preferred version) has been available since
at least 2.3
-tkc
--
http://mail.python.org/mailman/listinfo/python-list
Andre Engels wrote:
[...]
b = a.__iter__()
b.next()
> 'cat'
b.next()
> 'dog'
NOTE CORRECTION BELOW! IT'S next(b), not b.next() which doesn't exist in
Python 3 (if you need it, it's now b.__next__()). sorry.
not sure from what version, but certainly in 2.6 and on, you can improve
Andre Engels wrote:
[...]
b = a.__iter__()
b.next()
> 'cat'
b.next()
> 'dog'
not sure from what version, but certainly in 2.6 and on, you can improve
the syntax slightly:
>>> b = iter(a)
>>> b.next()
andrew
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, Mar 17, 2009 at 12:24 PM, Andre Engels wrote:
> On Tue, Mar 17, 2009 at 12:12 PM, Anjanesh Lekshminarayanan
> wrote:
> a = ['cat','dog','elephant']
> a.next()
>> Traceback (most recent call last):
>> File "", line 1, in
>> AttributeError: 'list' object has no attribute 'next'
>>
On Tue, Mar 17, 2009 at 12:12 PM, Anjanesh Lekshminarayanan
wrote:
a = ['cat','dog','elephant']
a.next()
> Traceback (most recent call last):
> File "", line 1, in
> AttributeError: 'list' object has no attribute 'next'
> Is there something that imtates PHP's next() ? (http://php.
>>> a = ['cat','dog','elephant']
>>> a.next()
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'list' object has no attribute 'next'
>>>
Is there something that imtates PHP's next() ? (http://php.net/next)
--
http://mail.python.org/mailman/listinfo/python-list
14 matches
Mail list logo