【发布时间】:2019-05-03 13:54:17
【问题描述】:
我想在 .py 文件中创建一个所有函数的列表,然后随机使用这些函数。 我已经使用 dir() 创建了一些列表,但无法运行。
带有函数file.py的文件:
def f1:
# some code
def f2:
# some code
def f3:
# some code
另一个脚本:
functions = dir(file)
random.choice(functions)()
显示这个错误
TypeError: 'str' object is not callable
【问题讨论】:
-
也许这对你有帮助 --> stackoverflow.com/questions/3061/…