我在使用mysql-python, 在已建立的数据库上运行选择查询时遇到问题。问题是返回一个数字,Python称为 a long,而不是查询的数据 - 应该注意,这个数字对应于应该返回的记录数(我登录到数据库并运行查询从MySQL到确保)。
这是代码:
db = MySQLdb.connect(db = 'testdb', user='testuser', passwd='test', host='localhost', charset='utf8', use_unicode=True)
dbc = db.cursor()
result = dbc.execute("""SELECT %s FROM example_movie""", ('title',))
urls = [row[0] for row in result]
最后一点代码urls = [row[0] for row in result]是将所有内容放入列表中。
错误如下所示:
TypeError: 'long' object is not iterable
当我有 pythonprint result它返回:
('RESULT:', 52L)
result当我附上str(result)它时,它只返回数字52(不是long)
非常感谢任何帮助和建议!