Project

General

Profile

« Previous | Next » 

Revision 2254

Compare object()-based sentinel values using is. Where sentinel values must be compared using ==, use rand.rand_int() instead.

View differences:

iters.py
1 1
# Iterators and iterables
2 2

  
3
import rand
4

  
3 5
def is_iterable(value): return getattr(value, '__iter__', False)
4 6

  
5
# Sentinel to use in iter() if function return value should be ignored
6
iter_end = object()
7
# Sentinel to use in iter() if function return value should be ignored.
8
# Can't use object() because iter() compares sentinel using ==.
9
iter_end = rand.rand_int()
7 10

  
8 11
def func_iter(func):
9 12
    '''Used to iterate a generating function which raises StopIteration instead

Also available in: Unified diff