我在 tld_list.py 中有三个类似的函数。我正在处理 mainBase.py 文件。
我正在尝试创建一个变量字符串,它将通过遍历所有函数的列表来调用适当的函数。我的代码从函数名称列表中读取,遍历列表并在每次迭代时运行该函数。每个函数从不同的网站返回 10 条信息
我已经尝试了 2 种变体,在下面注释为选项 A 和选项 B
# This is mainBase.py
import tld_list # I use this in conjunction with Option A
from tld_list import * # I use this with Option B
functionList = ["functionA", "functionB", "functionC"]
tldIterator = 0
while tldIterator < len(functionList):
# This will determine which function is called first
# In the first case, the function is functionA
currentFunction = str(functionList[tldIterator])
选项A
currentFunction = "tld_list." + currentFunction
websiteName = currentFunction(x, y)
print(websiteName[1]
print(websiteName[2]
...
print(websiteName[10]
选项B
websiteName = currentFunction(x, y)
print(websiteName[1]
print(websiteName[2]
...
print(websiteName[10]
即使看不到它,我也会通过结束每个循环来继续循环迭代tldIterator += 1
由于相同的原因,这两个选项都失败了TypeError: 'str' object is not callable
我想知道我做错了什么,或者是否有可能在循环中使用变量调用函数
紫衣仙女
慕森王
MYYA
相关分类