Use cases for del

Grant Edwards grante at visi.com
Wed Jul 6 23:14:06 EDT 2005


On 2005-07-07, Leif K-Brooks <eurleif at ecritters.biz> wrote:

> Grant Edwards wrote:
>> 1) So I know whether an parameter was passed in or not. Perhaps
>>    it's not considered good Pythonic style, but I like to use a
>>    single method for both get and set operations.  With no
>>    parameters, it's a get.  With a parameter, it's a set:
>> 
>>    class demo:
>>       def foo(v=None):
>>           if v is not None:
>>               self.v = v
>>           return self.v              
>
> _NOVALUE = object()
> class demo:
>     def foo(v=_NOVALUE):
>         if v is _NOVALUE:
>             return self.v
>         else:
>             self.v = v

Apart from the change in the logic such that the set operation
doesn't return a value, how is that any different?  You're just
creating your own non-integer-value "None" object instead of
using the one built in to the language.

> But what's wrong with properties?

Huh?

-- 
Grant Edwards                   grante             Yow!
                                  at               TAILFINS!!... click...
                               visi.com            



More information about the Python-list mailing list