I have a text file containing multiple columns. I can successfully print all the items in the 2 columns I am interested in by using this code:
with open(file) as catalog:
for line in catalog:
column = line.split()
if not line.startswith('#'): #skipping column labels
x = float(column[3])
y = float(column[4])
Now if I add a print(x) command inside the 'if not' loop, it prints all of the x values. But if I put print(x) outside of the loop it only prints the last item. What I want is to be able to access the full array of x and y values anywhere in my code. I also need to be able to access the x/y array items individually, so I can say x[2], and it will give me the third value in the x array. I can not get this part to work even inside of the 'if not' loop. Thanks for any help, I have only been using Python for a couple of weeks..
column = line.split()
inside theif not
block. The way it is now, you're wasting time splitting lines that you then discard.