[Python-Dev] redefining is (original) (raw)

Robert Brewer fumanchu at amor.org
Thu Mar 18 11:27:40 EST 2004


Barry Warsaw wrote:

On Thu, 2004-03-18 at 10:23, Jewett, Jim J wrote:

> There is an idiom (I've seen it more in Lisp than in python) > of creating a fresh object to act as a sentinel. A very common use case in Python is where None is a valid value in a dictionary: missing = object() if d.get('somekey', missing) is missing: # it ain't there It even reads well!

/Fu bonks himself in the forehead

That's so much nicer than the contortions I have gone through from time to time, not just for dicts, but arg lists. I was writing ugly crap like:

Something nobody would ever create

LessThanNothing = (0, -38, (None, '7 1/2')) def func(arg1, arg2, arg3=LessThanNothing): if arg3 == LessThanNothing: arg3 = None # or whatever the real default should be...

Bah. Thanks, Barry. :)

Robert Brewer MIS Amor Ministries fumanchu at amor.org



More information about the Python-Dev mailing list