[CentralOH] Detect last iteration of iterator

W. Matthew Wilson matt at tplus1.com
Mon May 9 19:16:01 CEST 2011


I stumbled across this looper class a long time ago:

https://bitbucket.org/ianb/tempita/src/f4a22b3ed511/tempita/_looper.py

It has what you're looking for, plus lots of other cute things.  At
some point, I might take this code, and some more bells and whistles,
and then make it into its own package.

Matt



On Mon, May 9, 2011 at 12:01 PM, Jon Miller <jonebird at gmail.com> wrote:
> Yeah, I like your first method better too, but a 'finally' clause
> popped into my head, so I thought I'd share it...
> In [1]: try:
>   ...:     for i in range(10):
>   ...:         print i
>   ...: except (Exception, e):
>   ...:     pass
>   ...: finally:
>   ...:     print 'Last call for alcohol %d' % i
>   ...:
>   ...:
> 0
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> Last call for alcohol 9
>
> -- Jon Miller
>
> On Mon, May 9, 2011 at 11:57 AM, Issac Kelly <issac.kelly at gmail.com> wrote:
>> You could use an enumerator, but I think your way here is cleaner.
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> http://mail.python.org/mailman/listinfo/centraloh
>>
>>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>



-- 
W. Matthew Wilson
matt at tplus1.com
http://tplus1.com


More information about the CentralOH mailing list