Run time default arguments

Chris Angelico rosuav at gmail.com
Thu Aug 25 19:30:59 EDT 2011


On Fri, Aug 26, 2011 at 6:54 AM,  <ting at thsu.org> wrote:
> def doSomething(debug=None):
>  debug = coalesce(debug,defaults['debug'])
>  # blah blah blah
>

It won't work with a True/False flag, but if you can guarantee that
all real options will evaluate as True, you can use a simpler
notation:

def doSomething(option=None):
  option=option or defaults['option']

You can't explicitly set option to False/0 with this, but it is a bit
cleaner (IMO - some may disagree).

ChrisA



More information about the Python-list mailing list