【发布时间】:2014-08-06 20:26:00
【问题描述】:
在 python 中我有这个代码
if record[0][1]:
问题是......当mysql没有返回任何东西时......
record[0][1]
没有数据..
此 python 代码失败:
if record[0][1]:
IndexError: tuple index out of range
我只是希望它继续执行“else”语句,或者只是将这个 if 语句视为 .. 考虑到这一点是无效的
record[0][1]
没有价值。或数据..(从 mysql 传入的东西)
【问题讨论】:
-
你总是可以
try: ... except IndexError: ...
标签: python python-2.6