On Aug 25, 3:30 pm, [email protected] wrote:
> What is the most common way to handle default function arguments that
> are set at run time, rather than at compile time? The snippet below is
> the current technique that I've been using, but it seems inelegant.
>
> defaults = { 'debug' : false }
> def doSomething (debug = None):
> debug = debug if debug != None else defaults['debug']
> # blah blah blah
You're close to the usual idiom:
def doSomething(debug=None):
if debug is None:
debug = defaults['debug']
...
Note the use of 'is' rather than '=='
HTH
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list