Re: Run time default arguments

2011-08-27 Thread Stephen Hansen
On 8/25/11 1:54 PM, [email protected] wrote: > On Aug 25, 10:35 am, Arnaud Delobelle wrote: >> 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 > > Hmm, from

Re: Run time default arguments

2011-08-27 Thread Carl Banks
On Thursday, August 25, 2011 1:54:35 PM UTC-7, [email protected] wrote: > On Aug 25, 10:35 am, Arnaud Delobelle wrote: > > You're close to the usual idiom: > > > > def doSomething(debug=None): > >     if debug is None: > >         debug = defaults['debug'] > >     ... > > > > Note the use of 'is' rat

Re: Run time default arguments

2011-08-25 Thread Chris Angelico
On Fri, Aug 26, 2011 at 6:54 AM, 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(o

Re: Run time default arguments

2011-08-25 Thread ting
On Aug 25, 10:35 am, Arnaud Delobelle wrote: > 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 Hmm, from what you are saying, it seems like there's no elegant wa

Re: Run time default arguments

2011-08-25 Thread MRAB
On 25/08/2011 15:30, [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 doSomethin

Re: Run time default arguments

2011-08-25 Thread Arnaud Delobelle
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 do

Run time default arguments

2011-08-25 Thread ting
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