谁能帮我解决以下两个问题:循环错误。和空变量
1)考虑下面的代码:如果我打印Listposblocks_COG1它会返回一个空变量。我究竟做错了什么。请注意,'结果'变量要大得多,但我只复制了一小段。 2)考虑下面的代码:如果我打印Listposblocks_COG2或Listposblocks_COG3 Ireceive错误消息:NameError:name'Listposblocks_COG2'未定义。我在这里做错了什么?
谢谢。
#Only part of the table, but it would take too much space.
results = [[336350.0, 7089650.0, -7.0, 0.1665, 1.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [336350.0, 7089650.0, -5.0, 0.1542, 1.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [336350.0, 7089650.0, -3.0, 0.2259, 1.5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], [336350.0, 7089650.0, -1.0, 0.2753, 1.5, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0]]
Start_index_nulzero = int(Length_Data_BM_Sorted)
if Start_index_nulzero == 5:
Listposblocks_COG1 = []
for i in results:
if results[5] == 1:
Listposblocks_COG1.append(i)
if type(results[6]) == int:
Listposblocks_COG2 = []
for i in results:
if results[6] == 1:
Listposblocks_COG2.append(i)
if type(results[7]) == int:
Listposblocks_COG3 = []
for i in results:
if results[7] == 1:
Listposblocks_COG3.append(i)
print Listposblocks_COG1
print Listposblocks_COG2
print Listposblocks_COG3
代码中没有打印声明 – Railslide
在我的真实脚本中有。然后它返回并清空Listposblocks_COG1,并为COG2和COG3提供了在问题2中命名的错误。 – AlmostGr
你为什么认为这些名字应该存在? –