What value should be passed to make a function use the default argument value?
LaundroMat
Laundro at gmail.com
Wed Oct 4 06:13:38 EDT 2006
Antoon Pardon wrote:
> The problem is like the following.
>
> def f(var=1):
> return var*2
>
> def g():
> arg = None
> try:
> arg = Try_Processing() / 3 + 1
> except Nothing_To_Process:
> pass
> if arg is None:
> return f()
> else:
> return f(arg)
>
> Now in this case you could start by assigning arg the value 1 and
> eliminate the if test. However that only works if you know the
> default value for the argument. What he seems to be asking for
> is if there is an object, (let as call it Default), that would
> make code like:
>
> def f(var=1):
>
> Equivallent to:
>
> def f(var=Default)
> if var is Default)
> var = 1
>
> So that we could write the following without the need of the
> f's default value.
>
> def g():
> arg = Default
> try:
> arg = Try_Processing() / 3 + 1
> except Nothing_To_Process:
> pass
> f(arg)
>
> --
> Antoon Pardon
Exactly. Thanks for helping out.
More information about the Python-list
mailing list