Calling superclass method with variable args?
David Arnold
arnold at dstc.edu.au
Thu Jul 15 17:29:56 EDT 1999
-->"Steve" == Steve Johnson <slj at pixar.com> writes:
Steve> But what if the method takes unnamed positional and keyword
Steve> arguments. Then, how do you pass these along to the
Steve> superclass's version of the method such that it gets the
Steve> arguments in the same form that the subclass's method did?
so close! the trick is the built-in function "apply(func, args [,
keywords])" has the optional keywords dictionary as a third parameter.
<http://www.python.org/doc/current/lib/built-in-funcs.html>
so,
class Job(Task):
def __init__(self,a,b,c, *moreargs, **morekeyargs):
apply(Task.__init__, (self,a,b,c) + moreargs, morekeyargs)
<whatever>
aJob = Job(x,y,z,m1,m2,m3,m4,m5,foo="bar")
should work just fine,
d
More information about the Python-list
mailing list