How to call a method with variing arguments
malcolm at commsecure.com.au
Tue Jul 3 09:22:14 CEST 2001
On Mon, Jul 02, 2001 at 11:40:49PM -0700, Heiko wrote:
> I want to do this:
> ClassObject = Class()
> ClassObject.Method(Arg1, Arg2, Arg3)
> ClassObject.Method(Arg1, Arg2, Arg3, Arg4, Arg5 ....)
> and so on.
> Means that I want to call a method with a variing number of arguments
> and the method decides what to do.
Define Method as
def Method(self, *args):
# stuff goes here
Inside this method, 'args' will be a tuple of the arguments in the order
they are passed and you can do whatever you like with them. Look at the
page ref/function.html in the Language Documentation for more
information (about halfway down that page).
> If possible, it would be nice, if the sequence of the arguments
> doesn´t matter, and the method realizes which argument is on which
> position (but that is a "nice to have").
I don't really know what you mean here, since I don't know how the
function is meant to know which argument belongs where.
Kleptomania: take something for it.
More information about the Python-list