Storing empties

Alex Martelli aleax at mail.comcast.net
Tue Nov 1 00:16:41 EST 2005


Aahz <aahz at pythoncraft.com> wrote:

> In article <1h58k4p.12xd7rj1t5peh0N%aleaxit at yahoo.com>,
> Alex Martelli <aleaxit at yahoo.com> wrote:
> >
> >the canonical idiom when you need such distinction is:
> >
> >_not_there = object()
> >def foo(bar=_not_there, baz=_not_there, bap=_not_there):
> >    if bar is _not_there: ...
> >
> >Other unique objects can be substituted for the 'sentinel', but I prefer
> >an empty "object()" because it has no other possible meaning except that
> >of a distinguishable, identifiable sentinel.  IOW, you could set the
> >_not_there name to [] or {} or many other things, but that could be
> >slightly confusing for the reader (since the other things might have
> >other meanings and purposes) while 'object()' shouldn't be.
> 
> What's your preferred idiom when you're dealing with storable objects?

What's a "storable object"?  You mean, something that can be pickled, or
passed to the .write method of a file object, or stored in a database,
or what else?


Alex



More information about the Python-list mailing list