在python中将fetch_all数组转换为单个数组

时间:2017-03-03 10:29:03

标签: python arrays

在python中,我从数据库中获取了数据。

SENTENCE = "It is wonderful. I'am happy"
sent= (word_tokenize(SENTENCE))

cursor = conn.cursor()
format_strings = ','.join(['%s'] * len(sent))
cursor.execute("SELECT emotion_type FROM emotion WHERE key_word IN (%s)" % format_strings,tuple(sent))
results = cursor.fetchall()
for i in results:
        z= (i)

输出

('happy',)
('happy',)

但我想把这个结果作为

['happy','happy']

如果有任何可能的方法来获得我想要的输出。请帮帮我!

1 个答案:

答案 0 :(得分:1)

如果结果只来自一个列,那么您可以随时执行

results = [res[0] for res in cursor.fetchall()]