-
Notifications
You must be signed in to change notification settings - Fork 1
/
fileio.py
42 lines (39 loc) · 1.24 KB
/
fileio.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy
from numpy import double
def tofile(filename,*args):
f = open(filename,"w")
length=[]
#print args
for col in args:
#print col
length.append(len(col))
def ithitem(i,*pargs):
items=[]
for table in pargs:
for col in table:
#print i,col[i]
items.append(col[i])
return items
for i in range(min(length)):
outputline=''
for item in ithitem(i,args):
outputline=outputline+"%s " % item
print >> f, outputline
#f.write(formatstr % ithitem(i,args))
f.close()
return len(length)
def readcol(file,n):
res=[]
infile = open(file,"r")
array = infile.readlines()
for line in array:
line = line.split()
try:
res.append(int(line[n]))
except ValueError:
res.append(line[n])
return numpy.array(res)
if __name__ == '__main__':
print "supported functions:"
print "readcol(filename,N)"
print "tofile(filename,*arrays)"