使用参数列表调用Python可调用对象
简单的问题:我怎么能把一串参数传给一个可以调用的Python函数呢?
假设我想从命令行调用一个函数,像这样:
my_script.py foo hello world
用下面这个脚本:
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:])
我相信一定有办法做到这一点,但我可能没注意到。