概述
我有以下方法,我从表中选择所有的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所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复