Storing empties (was Re: Automatic binding of **kwargs to variables)
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Storing empties (was Re: Automatic binding of **kwargs to variables)

From: Aahz <aahz@pythoncraft.com>
Date: Mon Oct 31 2005 - 23:52:54 CET

In article <1h58k4p.12xd7rj1t5peh0N%aleaxit@yahoo.com>,
Alex Martelli <aleaxit@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?

-- 
Aahz (aahz@pythoncraft.com)           <*>         http://www.pythoncraft.com/
"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair
Received on Mon Nov 21 01:09:29 2005