What value should be passed to make a function use the default argument value?

Antoon Pardon apardon at forel.vub.ac.be
Wed Oct 4 06:38:41 EDT 2006


On 2006-10-04, Nick Craig-Wood <nick at craig-wood.com> wrote:
> Antoon Pardon <apardon at forel.vub.ac.be> wrote:
>>  One possible way to do what I think you want is to code as follows:
>> 
>>  class Default (object):
>>    pass
>
> I'd have written
>
> Default = object()
>
>>  def f(var=Default):
>>    if var is Default:
>>      var = 1
>>    return var * 2
>
> But yes, defining a sentinel like this is a good idea.

The problem is that a lot of built in and library functions
are not written this way. So when f is one of those, you
are stuck.

-- 
Antoon Pardon



More information about the Python-list mailing list