PDA

View Full Version : Reading in columns


sxu04
01-25-2012, 02:33 AM
Hi, I'm hoping someone can help

I have a text file that I need to read in, and I want to be able to loop through both rows and columns

Column 1 and 2 in the text file contains a list of 64 numbers relating to 64 x and y positions. Column 3 contains a list of 64 numbers (either 1 or 2) that relates to a certain action in my vizard code.

Currently, I can loop through each row in columns 1 and 2 checking whether these values match their current position, when it matches - the number in the corresponding row in column 3 is read in and the action is carried out.

So far so good, but rather than having just one 'action' column I actually have 100+ action columns (columns 3 -100+) and I want to create a loop where each step in the loop reads the next action colomn in the text file

Any help would be most appreciated!

import viz
viz.go()

currentX=[]
currentY=[]
action=[]

file = open('data.txt', 'r')

for line in file:
s=line.split()
currentX.append(float(s[0]))
currentY.append(float(s[1]))
action.append(float(s[2]))

def movement(key):
currentpos = viz.MainView.getPosition()
for i in range(0,64):
if currentpos==[currentX[i],1.0,currentY[i]]:
if action[i]==1:
.....