Sentinel values for special cases

Aahz aahz at
Fri Oct 27 16:40:30 CEST 2006

In article <mailman.1308.1161912647.11739.python-list at>,
Ben Finney  <ben at> wrote:
>Fourth, if you have decided that a magic sentinel value is called for
>but None is already taken for some other purpose, don't use a
>string. Use a unique do-nothing object, defined at the module level so
>callers can easily get at it, like 'Dmitry Vasiliev' showed
>[reproduced below].
>    GLOBAL = object()
>    def insert_ids(ids=GLOBAL):
>        if ids is GLOBAL:
>            ids = get_global_ids()

The one disadvantage of this approach is that it complicates pickling
if/when you store the stentinel in an instance.  There are ways of
working around that, but none are pleasant.
Aahz (aahz at           <*>

"If you don't know what your program is supposed to do, you'd better not
start writing it."  --Dijkstra

More information about the Python-list mailing list