Re: array next pointer

2009-03-18 Thread R. David Murray
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

Re: array next pointer

2009-03-18 Thread Hrvoje Niksic
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

Re: array next pointer

2009-03-18 Thread Duncan Booth
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

Re: array next pointer

2009-03-17 Thread Armin
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

Re: array next pointer

2009-03-17 Thread Luis Zarrabeitia
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

Re: array next pointer

2009-03-17 Thread R. David Murray
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

Re: array next pointer

2009-03-17 Thread Benjamin Peterson
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

Re: array next pointer

2009-03-17 Thread Luis Zarrabeitia
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

Re: array next pointer

2009-03-17 Thread Tim Chase
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

Re: array next pointer

2009-03-17 Thread andrew cooke
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

Re: array next pointer

2009-03-17 Thread andrew cooke
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

Re: array next pointer

2009-03-17 Thread Andre Engels
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' >>

Re: array next pointer

2009-03-17 Thread Andre Engels
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.

array next pointer

2009-03-17 Thread Anjanesh Lekshminarayanan
>>> 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