我在stackoverflow上找到了这个脚本,这有助于我将参数从一个函数传递到另一个函数:
def perform( fun, fun2, *args ):
fun(*args)
fun2(*args)
def action1(filename, destination):
print filename, destination
def action2(filename, destination):
print 'help me find my {}'.format(filename)
print 'it is located at {}'.format(destination)
perform(action1, action2, 'text.csv','/User/username/Desktop')
结果:
text.csv /User/username/Desktop
help me find my text.csv
it is located at /User/username/Desktop
但是......如果action1
或action2
在另一个python .py文件中怎么办?我可以导入它们,但不确定如何使它的行为与上面相同。
感谢任何帮助。
答案 0 :(得分:1)
from usermodule1 import action1, action2
from usermodule2 import perform
perform(action1, action2)
usermodule1.py - .py file with defined action1, action2 functions usermodule2.py - .py file with defined perform funtion