python - 在python中调用函数时替换函数的变量?
问题描述
对不起,我的英语不好。
有没有办法从外部替换方法的变量?
假设我有两个文件 app.py 和 try.py。
在应用程序中 -
def call():
c=5
return c
在尝试 -
from app import *
c=1000
d=call()
print(d)
当我运行 try 时,我希望输出为 1000 而不是 6。有没有办法做到这一点?
解决方案
*在 app.py 中:*
def call(c=5):
return c
*在try.py中:*
from app import *
d=call(1000)
print(d)