Idiom gone, or did it really ever exist? () is ()

Steve Purcell stephen_purcell at yahoo.com
Wed Apr 18 02:11:47 EDT 2001


Mike C. Fletcher wrote:
> Over the years, I've occasionally used this idiom:
> 
> NULLARGUMENT = ()
> 
> def someFunctionOrMethod  (argument = NULLARGUMENT ):
>     if argument is NULLARGUMENT:
>         doSomething()
>     else:
>         doSomethingElse()
> 
> That is, I was attempting to distinguish between a call where argument is
> passed a NULL tuple and a call where argument is passed nothing at all.
> When I was working on unit tests for my current piece of code, however, I
> discovered that this no longer works (Python 1.5.2).  No idea for how long
> it hasn't worked.  Now, of course, I could have used:


The convention is to use 'None' for this purpose. 'None' never changes, so
'argument is None' will work correctly for you.

-Steve


-- 
Steve Purcell, Pythangelist
Get testing at http://pyunit.sourceforge.net/
Any opinions expressed herein are my own and not necessarily those of Yahoo




More information about the Python-list mailing list