所以,我完全清楚 evil eval()
是怎样的,但是我如何使用它?假设我有一个字符串"func(arg1, arg2)"
然后我将其分隔为["func", "arg1", "arg2"]
。我如何使用eval()
来使用splat来运行函数中的每个参数。
示例:
funcs = ("saySomething", "yellTaco")
def saySomething(something):
print(something)
def yellTaco(times):
for i in range(times):
print("TACO")
c = input("> ") # Let's say I input: "saySomething your-mom"
c = c.split(" ")
if c[0] in funcs:
eval(c[0]+"("+[HOW DO I PUT A SPLAT FOR THE REST OF THE TABLE HERE?]+")")
答案 0 :(得分:1)
将它们变成以逗号分隔的字符串。
', '.join(c[1:])