Ask Your Question

# Revision history [back]

Suppose that you have a file '/tmp/DataFile' containing the following text

3;2
2;1
1;0.1
0.01;-0.9


Then you can load the two data columns into two arrays xArr and yArr by the following code

f = open('/home/tobi/tmp/DataFile', 'r')

xArr=[]
yArr=[]
line=f.readline()
while(line !=''):
xy=line.split(';')
xArr.append(float(xy[0]))
yArr.append(float(xy[1]))
line=f.readline()


Now you can do whatever you want with these array, for example plot them

list_plot(zip(xArr,yArr))


If you like to understand better what open and readline does look at Python doc input output, the split command is explained in the Python doc on strings