databases=mycursor.fetchall()
print(databases)
print(databases[0])
print(databases[0][0])
执行结果:
(('catfish-finance',), ('information_schema',))
('catfish-finance',)
catfish-finance
#fetchall获取的是元组,里面包含多余的括号和逗号没法直接用,通过以下两种方式遍历,获取表名
new_databases=[tuple[0] for tuple in databases] (这个写法效果等同下面)
print(new_databases)
new_databases=[]
for tuple in databases:
new_databases.append(tuple[0])
print(new_databases)
#执行结果:['catfish-finance', 'information_schema']