Passing multiple parameters to a Python method: the * tag
Posted by jpluimers on 2019/08/28
I had to pass parameters to a method so they became a list:
threadManager.append( UrlMonitorThread(monitor, "http://%s" % targetHost), SmtpMonitorThread(monitor, targetHost, 25), SmtpMonitorThread(monitor, targetHost, 587), SshMonitorThread(monitor, targetHost, 22))
This appeared much easier than I anticipated:
def append(self, *threads): for thread in threads: self.threads.append(thread)
It uses the *
tag which is explained here:
- [WayBack] In the following method definitions, what does the * and ** do for param2? def foo(param1, *param2): def bar(param1, **param2)
- [WayBack] Pass array as argument in python
- [WayBack] Python tutorial – Parameter Passing: “call by value” and “call by name”
- [Archive.is] 4.7.3. Control Flow Tools – Defining Functions – Arbitrary Argument Lists
–jeroen
Leave a Reply