End of file
Nick Craig-Wood
nick at craig-wood.com
Fri Oct 8 03:29:57 EDT 2004
Alex Martelli <aleaxit at yahoo.com> wrote:
> > sentinel = []
>
> It's fine, but I would still suggest using the Canonical Pythonic Way To
> Make a Sentinel Object:
>
> sentinel = object()
>
> Since an immediate instance of type object has no possible use except as
> a unique, distinguishable placeholder, ``this thing here is a sentinel''.
Yes a good idiom which I didn't know (still learning) - thanks!
This only works in python >= 2.2 according to my tests.
Its also half the speed and 4 times the typing
$ /usr/lib/python2.3/timeit.py 'object()'
1000000 loops, best of 3: 0.674 usec per loop
$ /usr/lib/python2.3/timeit.py '[]'
1000000 loops, best of 3: 0.369 usec per loop
But who's counting ;-)
--
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick
More information about the Python-list
mailing list