forwarding *arg parameter
Tuomas
tuomas.vesterinen at pp.inet.fi
Sun Nov 5 12:42:30 EST 2006
Steven D'Aprano wrote:
<snip>
> You could write something like this:
>
> def g(*arg):
> # Detect the special case of a single tuple argument
> if len(arg) == 1 and type(arg[0]) == tuple:
> return arg[0]
> else:
> return arg
>
> but now tuple arguments are treated differently to all other data. Why do
> you think you need that?
I am looking a shorter way to do the above in the case:
def g(*arg):
return arg
def f(*arg):
return g(arg)
How can g know if it is called directly with (('foo', 'bar'),) or via f
with ('foo', 'bar'). I coud write in f: return g(arg[0], arg[1]) if I
know the number of arguments, but what if I don't know that in design time?
TV
More information about the Python-list
mailing list