On Feb 4, 6:53 am, André Malo <[EMAIL PROTECTED]> wrote:
> * Steven D'Aprano wrote:
> > On Sun, 03 Feb 2008 15:31:49 -0800, Paul Boddie wrote:
>
> >> I don't know whether I can offer much better advice than others, but I
> >> have noticed that a lot of my own code has moved in the direction of not
> >> having specific default values in function/method signatures. So,
> >> instead of this...
>
> >>   def f(x=123):
> >>     ...
>
> >> ...I have this:
>
> >>   def f(x=None):
> >>     if x is None:
> >>       x = 123
>
> > For the love of Pete, WHY??????
>
> > I understand why you would do it for a mutable default, but immutable???
>
> I'm observing myself doing the same, for the following reason:
>
> Consider the function being part of a bigger system, where it's called from
> another function or method which should "inherit" the default value of the
> function, like:
>
> def g(foo, bar, x=None):
>    ...
>    f(x=x)
>
> Now if you change the default value of f(x) for some reason, you don't have
> to wind up all the possible caller signatures to reflect that change.

You might find handy a decorator I've written exactly for this
scenario, reusing default arguments across functions:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440702

George
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to