好的,所以我从sqlite数据库中提取一些数据,在向用户显示时我无法弄清楚如何正确格式化它们......我正在使用python 2.5。
studentid = raw_input("Enter your student ID: ")
cur.execute('SELECT APP_DECISION FROM APP_STATUS WHERE STUDENTID = ?', (studentid,))
appdecision = cur.fetchall()
cur.execute('SELECT GRANT FROM FINAID WHERE STUDENTID = ?', (studentid,))
grant = cur.fetchall()
if (appdecision == 'ACCEPTED'):
print 'congratulations'
else:
print 'sorry'
print (appdecision)
print (grant)
结果是这样打印的,
Enter your student ID: 100006
[(u'ACCEPTED',)]
[(9500,)]
我希望能够打印出来,例如Accepted和$ 9500 ....如何检查具体值,以便祝贺已被接受的用户? 非常感谢!
答案 0 :(得分:1)
将其打印为:
print (appdecision[0][0])
print (grant[0][0])
这是因为[(u'ACCEPTED',)]
是一个包含元组的列表,其中包含字符串"ACCEPTED"
。同样,您必须检查这样的值:
if appdecision[0][0] == "ACCEPTED":
print "Congratulations!"