What value should be passed to make a function use the default argument value?

Paul Rubin http
Wed Oct 4 07:34:48 EDT 2006


Antoon Pardon <apardon at forel.vub.ac.be> writes:
> repeat(object[, times])
>     Make an iterator that returns object over and over again. Runs
>     indefinitely unless the times argument is specified. ...
> 
> My first impression from this, is that it is possible to call
> this as follows:
>   repeat(None, times = 5)
> But that doesn't work either.

The code and/or doc is wrong, you have to use a positional arg
and not a named one.  repeat(None, 5) does the right thing.

> That wont help much if you would like something like the following:
> 
>    def fun(f):
> 
>      arg = Default
>      try:
>        arg = Try_Processing()
>      except Nothing_To_Process:
>        pass
>      f(arg)

Write it like this:

    def fun(f):
      args = ()
      try:
        args = (Try_Processing(),)
      except Nothing_To_Process:
        pass
      f(*args)



More information about the Python-list mailing list