我有大约20个python函数类:
class class_1:
def display():
return('This is 1st Class')
class class_2:
def display():
return('This is 2nd Class and some more lines')
#Like this 20 class I have
现在,何时调用存储在数据库中的类:
标签
|
班
|
地位
|
ab
|
2.
|
0
|
光盘
|
三
|
1.
|
ef
|
1.
|
0
|
生长激素
|
1.
|
1.
|
现在,当我运行以下代码时:
data = db_fetchquery("SELECT class FROM table WHERE status = '0'")
for row in data:
display = class_{row[0]}.display()
print(display)
我期待的结果是:
这是二等舱,还有更多的线路
这是头等舱
但我越来越
SyntaxError:无效语法
我还试过字典:
data = db_fetchquery("SELECT class FROM table WHERE status = '0'")
for row in data:
id = {'x' : 'class_'+row[0]}
display = id['x'].display()
这让我
AttributeError:“str”对象没有“display”属性