End of file

Alex Martelli aleaxit at yahoo.com
Thu Oct 7 18:36:11 CEST 2004


Nick Craig-Wood <nick at craig-wood.com> wrote:
   ...
> You'll note I use the spurious sentinel local variable to mark unused
> values rather than None (which is likely to appear in a general
> list).  I think this technique (which I invented a few minutes ago!)
> is guaranteed correct (ie sentinel can never occur in iterator).
   ...
>     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 way you're "strongly saying"
``this thing here is a sentinel''.  An empty list _might_ be intended
for many other purposes, a reader of your code (assumed to be perfectly
conversant with the language and built-ins of course) may hesitate a
microsecond more (looking around the code for other uses of this
object), while the CPWtMaSO shouldn't leave room for doubt...


Alex



More information about the Python-list mailing list