【发布时间】:2016-05-16 20:06:37
【问题描述】:
我有一个 GUI,它允许用户从特定的 *.py 文件运行任何功能。我希望某些功能以彼此不同的方式运行。为了做到这一点,我试图将属性附加到函数(简单的事情,比如它需要哪些输入)。但是,我发现获取这些属性的唯一方法是先运行代码。
有没有一种方法可以在不运行代码的情况下获取这些属性,或者可能是一种更 Python 的方式来处理这个任务?
我的代码的非常基本的示例:
文件A.py
def Beta(x):
Beta.input_stype = "Float"
y = x + 0.5
return y
def Gamma(x):
Gamma.input_stype = "String"
y = x + "_blah_blah_blah"
return y
def Delta(x):
Delta.input_stype = "String"
y = x.index('WhereIsIt')
return y
文件B.py
import FileA
import inspect
z = inspect.getmembers(Fiddle2, inspect.isfunction)
#### User selects the code value here ####
x = user_selection
executable = z[x][1] # Pulls the executable code
if executable.input_stype == "Float" :
y = executable(45)
elif executable.input_stype == "String" :
y = executable('Testing_the_WhereIsIt_stuff')
【问题讨论】:
标签: python