我还是 web2py 和 python 的新手,在我的 web2py 应用程序中,我创建了这个在 python shell 中运行良好的代码。
python 模块:这些方法的工作方式是用户输入方程式查询以获得答案。如果是添加,method1 会解决它,与调用其他方法来执行不同代码的方法相同,例如
def method1():# to do additions
name = input('Please Enter equation here: ').lower()
if '1 + 1':
answer = code
return answer
def method2():# to do subtractions
name = input('Please Enter equation here: ').lower()
if '1 - 1':
answer = code
return answer
在控制器中,我导入了如下方法,尽管方法比显示的要多得多
from applications ...... import method1
from applications ...... import method2
from applications ...... import method3
from applications ...... import method4
method1 = method1
method1 = method2
method1 = method3
method1 = method4
G0 = [method1, method2, method3, method4]
def Foo():
code..
for (func) in G0:
return func()
问题是仅调用列表中位置 [0] 处的方法 1,而不调用其他方法。当用户输入任何查询时,我想随机调用任何方法。