Tôi đã nhận lỗi sau:Lỗi Loại: 'int' đối tượng không phải là iterable - Python
File "/home/ec2-user/test/test_stats.py", line 43, in get_test_ids_for_id
cursor.execute("""select test_id from test_logs where id = %s """, (id))
File "/home/ec2-user/.etl/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute
query = query % tuple([db.literal(item) for item in args])
TypeError: 'int' object is not iterable
Dưới đây là phần mã của tôi, tôi đang gặp rắc rối với:
def get_test_ids_for_id(prod_mysql_conn, id):
cursor = prod_mysql_conn.cursor()
cursor.execute("""select test_id from test_logs where id = %s """, (id))
rows = cursor.fetchall()
test_ids = []
for row in rows:
test_ids.append(row[0])
return test_ids
Điều đó sẽ được 'cursor.execute (... , (id,)) '- lưu ý dấu phẩy, làm cho nó trở thành một bộ dữ liệu. – jonrsharpe
@jonrsharpe Bạn có thể giải thích rõ ràng không? – brisk
Martijn đã có! Xem ví dụ http://stackoverflow.com/q/22460082/3001761 – jonrsharpe