在分配pylint(E0601)之前使用变量“ criteria_names” 。 仅针对已分配的“ criteria_names”列表弹出此错误,而不会以相同的方式弹出其他列表。任何指针或解决方案都非常感谢!
代码片段:
data = list()
lines = list()
n_vectors = list()
vectors = list()
medium_vectors = list()
classnames = list()
classes_insert_lines = list()
vectors_raw = list()
criteria_names = list()
def DataGet(temp_pulse_file):
data[:] = []
n_vectors[:] = []
vectors[:] = []
medium_vectors[:] = []
classnames[:] = []
classes_insert_lines[:] = []
vectors_raw[:] = []
criteria_names[:] = [] #<- this is where the error pops up
with open(temp_pulse_file, "r", encoding='utf-8') as file:
lines = (file.read()).split("\n")
file.close()
n = -1
for i in range(len(lines)):
data.append(lines[i].split(","))
if data[i][0] == ">":
n += 1
classnames.append(data[i][1])
classes_insert_lines.append(i + 1)
n_vectors.append(0)
vectors_raw.append([])
vectors.append([])
elif data[i][0] == "#":
weights = data[i][1:]
elif data[i][0] == "$":
criteria_names = list(data[i][1:])
else:
n_vectors[n] += 1
vectors[n].append(data[i])
vectors_raw[n].append(lines[i])
n_elems = len(vectors[0][0])
classes = len(classnames)
for i in range(classes):
for j in range(n_vectors[i]):
for k in range(n_elems):
vectors[i][j][k] = float(vectors[i][j][k])
return n_elems, classes, n_vectors, weights, lines, classes_insert_lines, vectors_raw
n_elems, classes, n_vectors, weights, lines, classes_insert_lines, vectors_raw = DataGet(getcurrentdir() + 'db.pulse')
print(' criteria_names:',criteria_names)
当我删除criteria_names[:] = []
时,该函数中使用的其他列表没有任何错误。任何帮助。
答案 0 :(得分:0)
感谢@martineau和@Barmar,在global criteria_names
函数的开头添加了DataGet()
,这确实是一个奇迹。