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



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

.



Relevant Pages