Re: another newbie question: why should you use "*args" ?
- From: "Diez B. Roggisch" <deets@xxxxxxxxxxxxx>
- Date: Wed, 31 Jan 2007 12:57:56 +0100
stef wrote:
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.
So the simple conclusion might be: never use "*args",
or am I overlooking something ?
Yup. For example decorators, that wrap functions. If you do that, you want
to return a function that captures all passed arguments, does something,
and then invokes the original function with the original arguments. Like
this:
def logging_decorator(f):
def _f(*args, **kwargs):
print "calling %r with (%r, %r)", % (f, args, kwargs)
return f(*args, **kwargs)
return _f
@logging_decorator
def im_just_a_function(some, argument, and, other=None):
pass
Diez
.
- References:
- Prev by Date: Regex with ASCII and non-ASCII chars
- Next by Date: Re: another newbie question: why should you use "*args" ?
- Previous by thread: another newbie question: why should you use "*args" ?
- Next by thread: Re: another newbie question: why should you use "*args" ?
- Index(es):
Relevant Pages
|