[Tutor] Problem with default arguments for function
Dick Moores
rdm at rcblue.com
Mon Nov 12 04:07:46 CET 2007
At 04:22 PM 11/11/2007, Alan Gauld wrote:
>"Dick Moores" <rdm at rcblue.com> wrote
>
> > And if the function is rewritten as def fact(n, full=False,
> > precision=15)
> > there would be the analogous problem involving full.
> >
> > Is there a way to solve this problem of the unnecessary setting of
> > the 2nd argument?
>
>The most common solution I've seen is to write wrappers
>around the basic function like:
>
>def fullFact(n, precision=15):
> return fact(n,True,precision)
>
>def precisionFact(n, full=False):
> return fact(n, full, 15)
>
>Not terribly elegant but is at least short and simple.
Alan, I won't adopt this solution for my fact(), but I'm glad to know about it.
Thanks,
Dick
More information about the Tutor
mailing list