On 2 avr, 22:32, "Primoz Skale" <[EMAIL PROTECTED]> wrote: > >> I also understand (fairly) how to collect arguments. For example, let's > >> define another function: > > >> def f(*a): > >> print a > > > This means that f takes any number of optional positional arguments. > > If nothing is passed, within f, 'a' will be an empty tuple. Note that > > this is *not* the usual way to define a function taking multiple > > (mandatory) arguments. > > M. Lutz in "Learning Python" had defined it this way. What is the *usual* > way in this case?
You mean : "what's the usual way to define a function taking multiple *mandatory* arguments" ? I'd think it's explained in your book ??? def f(a, b, c): print a, b, c But this is such a cs101 point that we're surely misunderstanding each other here. > > > or (slightly more involved, and certainly overkill): > > > def with_default_args(default): > > def decorator(func): > > def wrapper(*args): > > if not args: > > args = default > > return func(*args) > > return wrapper > > return decorator > > > @with_default_args((0,)) > > def f(*a): > > print a[0] > > Now, this is interesting. Thanks! :) Dont take this as a "recommanded" solution to your problem - it was (mostly) to be exhaustive (and a bit on the "showing off" side too to be honest). -- http://mail.python.org/mailman/listinfo/python-list