我是靠谱客的博主 狂野期待,最近开发中收集的这篇文章主要介绍python mysql 元组_Python:从mysql表中选择时,元组索引必须是整数,而不是str,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我有以下方法,我从表中选择所有的ID,并将它们附加到列表并返回该列表.但是当执行这个代码时,我最终得到元组指示必须是整数…错误.我已经附上错误和打印输出与我的方法:

def questionIds(con):

print 'getting all the question ids'

cur = con.cursor()

qIds = []

getQuestionId = "SELECT question_id from questions_new"

try:

cur.execute(getQuestionId)

for row in cur.fetchall():

print 'printing row'

print row

qIds.append(str(row['question_id']))

except Exception, e:

traceback.print_exc()

return qIds

打印我的方法:

Database version : 5.5.10

getting all the question ids

printing row

(u'20090225230048AAnhStI',)

Traceback (most recent call last):

File "YahooAnswerScraper.py", line 76, in questionIds

qIds.append(str(row['question_id'][0]))

TypeError: tuple indices must be integers, not str

最后

以上就是狂野期待为你收集整理的python mysql 元组_Python:从mysql表中选择时,元组索引必须是整数,而不是str的全部内容,希望文章能够帮你解决python mysql 元组_Python:从mysql表中选择时,元组索引必须是整数,而不是str所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部