Sentinel values for special cases

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


Gabriel Genellina <gagsl-py at yahoo.com.ar> writes:

> At Friday 27/10/2006 11:40, Aahz wrote:
> > Ben Finney wrote:
> > >    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.
>
> But why should you store the sentinel in an instance? It's only
> purpose is to detect a special case in the parameter, when None is
> not appropiate.

You might be storing values that will later become parameters to the
function.

    ids_to_be_processed_later = {
        'chin': [14, 7, 9],
        'bin':  foo.GLOBAL,
        'fin':  [74, 98, 12],
    }
    serialise_stuff()

-- 
 \          "The only tyrant I accept in this world is the still voice |
  `\                                       within."  -- Mahatma Gandhi |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list