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

Nick Craig-Wood nick at craig-wood.com
Wed Oct 4 12:30:04 CEST 2006


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.

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list