acting on items passed to a method via a dictiomary

Donnal Walter donnal at donnal.net
Mon Oct 18 21:59:37 CEST 2004


David M. Cooke wrote:
> "Diez B. Roggisch" <deetsNOSPAM at web.de> writes:
>>def foo(items=None):
>>    if not items is None:
> 
> 
> Or the more readable (IMO):
> 
> def foo(items=None):
>     if items is not None:
>        ...
> 
> They're equivalent, but a reader could see 'not items is None' as
> '(not items) is None)' [although it's not].
> 

As I mentioned in a previous post this morning, the default items = {} 
is now a somewhat irrelevant side-issue, but your comment here will help 
me in a dozen other locations. For some reason it had never occurred to 
me that "items is not None" would be equivalent to "not items is none" 
because I made a wrong assumption about the nature of the *is* operator. 
But a quick shell session shows that you are quite right.

 >>> x = None
 >>> not x is None
False
 >>> x is not None
False
 >>> y = {}
 >>> not y is None
True
 >>> y is not None
True
 >>>

Thank you.

Donnal Walter
Arkansas Children's Hospital





More information about the Python-list mailing list