another newbie question: why should you use "*args" ?

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Wed Jan 31 13:23:03 CET 2007


stef a écrit :
> 
> why should I use *args,
> as in my ignorance,
> making use of a list (or tupple) works just as well,
> and is more flexible in it's calling.

Err... How so ?

> So the simple conclusion might be: never use "*args",
> or am I overlooking something ?

Try writing generic higher order functions without it, and let us know.

dummy example:

def trace(func, *args, **kw):
   print "calling %s with %s %s" % (func.__name__, str(args), kw)
   try:
     result = func(*args, **kw)
     print "got %s" % str(result)
     return result
   except Exception, e:
     print "raised : %s" % e
     raise




More information about the Python-list mailing list