【发布时间】:2015-09-23 22:30:26
【问题描述】:
我在我的程序中遇到了一个奇怪的错误,我似乎无法在一个简化的示例中复制它。我正在尝试将 None 的值分配给列表中的项目,但由于某种原因它会引发错误。我不明白这个问题,因为我什至没有使用元组。
#Execute SQL query returning five columns.
cursor.execute(query)
#Iterate the rows.
for row in cursor:
#Get one row, and copy it to a new list variable.
my_list = row[:5]
#If index 3 is zero, convert it to None.
if (my_list[3] == 0):
print type(my_list[3])
##Prints <type 'int'>
my_list[3] = None
##TypeError: 'tuple' object does not support item assignment
【问题讨论】:
标签: python list tuples mysql-python