I wrote a small Python script below that is behaving in a way I did not anticipate, but I cannot pinpoint the error. Specifically, I have a variable xyz_all that I'd expect to be empty because I'm only ever appending an empty list to it, but in reality it contains the elements of xyz. How is this possible?
with open(filename,'r') as rf:
xyz = []
xyz_all = []
for line in rf:
if 'A' in line:
line = line.split()
xyz.append([float(j) for j in line[4:7]])
elif 'B' in line:
xyz = []
xyz_all.append(xyz)
print(xyz_all)