mysql 的查詢結果通常為元組列表,默認會多出一個逗號,處理方式也很簡單,在循環中做處理即可
cursor.execute('SQL')rows = cursor.fetchall()for row in rows: print(row) 改為for (row,) in rows: print(row)
測試
if __name__ == '__main__': a = (('AAA',), ('BBB',), ('CCC',)) for i in a: print(i) print('') for (i,) in a: print(i)結果('AAA',)('BBB',)('CCC',)AAABBBCCC