Wednesday, February 15, 2012

python code that separate 150000 records into 15 small files

fa = open ('b150000.txt','r')
n = 1
fb = open ('b-1.txt','w')
i = 0
for line in fa:
# 1 to 10000 for first 10001 to 20000 for second
if((i/10000 +1)!=n):
n=i/10000 + 1
fb.close()
fb = open('b-'+str(n)+'.txt','w')
fb.write(line)
i = i + 1
fa.close()
fb.close()

No comments:

Post a Comment