Simple question: How can I pass an arbitrary list of args to a python callable?
Let’s say I want to invoke a function from the command line, like so:
my_script.py foo hello world
with the following script:
import myfuncs
f = getattr(myfuncs, sys.args[1])
if f and callable(f):
# This is the bit I don't know. I effectively want f(sys.args[2:])
I’m sure there’s a way to do this, but I must be overlooking it.
You are looking for sequence unpacking. I.e.
f(*sys.argv[2:])