我有一个奇怪的 idea ,抓取一个列表项并将其称为模块函数,下面是我试图做的:
如果在random module上使用dir()
,它将返回其属性的列表,我想获取一个特定项,在本例中是randint,然后使用a,b作为参数将其作为工作函数调用,并变成以下形式randint(a, b)
from random import randint #to avoid the dot notation and make it simple
a = 10
b = 100
var = dir(random)
print(var)
# here is the result
#randint index is 55
print(var[55])
>>> randint
我无法找到函数randint()的类型,因此可以将列表项转换为它,然后try 以下操作:
something(var[55] + "(a, b)")
有什么方法可以实现我想要做的吗?