get a self data in a method call

Erik Max Francis max at alcyone.com
Sun Dec 22 20:48:21 EST 2002


Sean Ross wrote:

> # here's a shorter, if less obvious, version
> def func(self, data = None):
>            data = data or self.data

This is a bad idea, in my opinion.  Depending on the values you rightly
expect to pass in for data, this can have unintended side effects, since
it prevents you from passing in any data that evaluates to false (or,
rather, if you do so, you'll get the results of self.data instead). 
That includes 0, 0.0, 0L, (), [], {}, and an instance of a custom type
which has overloaded __nonzero__ to return something false.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ It's just a day that brings it all about
\__/ Sade
    Sade Deluxe / http://www.sadedeluxe.com/
 The ultimate Sade encyclopedia.



More information about the Python-list mailing list