Sentinel values for special cases

Ben Finney bignose+hates-spam at benfinney.id.au
Fri Oct 27 20:06:13 EDT 2006


aahz at pythoncraft.com (Aahz) writes:

> Ben Finney  <ben at benfinney.id.au> wrote:
> >Use a unique do-nothing object, defined at the module level so
> >callers can easily get at it [...]
> >
> >    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.

Hmm, and any other kind of serialisation would be similarly affected I
suppose.

What's an alternative?

-- 
 \      "Think for yourselves and let others enjoy the privilege to do |
  `\                       so too."  -- Voltaire, _Essay On Tolerance_ |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list