A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/070392.html below:

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

Idiom gone, or did it really ever exist? () is () Idiom gone, or did it really ever exist? () is ()Michael Haggerty mhagger at alum.mit.edu
Thu Apr 19 17:04:12 EDT 2001
"Delaney, Timothy" <tdelaney at avaya.com> writes:
> > > 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.
> 
> # Should always work
> 
> class nullArgument:
>     """"""
> 
> __nullArgument = nullArgument()
> 
> def func (p=__nullArgument):
>     if p is __nullArgument:
>         print 'Default parameter'
>     else:
>         print 'Parameter passed'

When I first faced this problem, I started typing in code that was
equivalent to yours, until it occurred to me that there is no reason
to instantiate the class--the class itself serves as a fine default
argument.  In other words,

    class __nullArgument:
    	pass # Isn't this what pass is for?

    def func (p=__nullArgument):
    	if p is __nullArgument:
    	    print 'Default parameter'
    	else:
    	    print 'Parameter passed'

Cheers,
Michael

-- 
Michael Haggerty
mhagger at alum.mit.edu

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4