Wednesday, February 15, 2012

python code that crumble data for test

following code that read big data(fixed length) file,and scruble the specified columns data to create new data to test.

from random import randint

fa = open ('a.bbb','r')
fb = open ('b.txt','w')
i = 0
for line in fa:
i= i + 1
if(i!=1):
s = list(line)
if(len(s)>500 and s[300]!=' ' and s[300]!= ''):
print s[300] + s[301]
delta = str(int(s[300]+s[301]) + i/5000 + 1)
if (len(delta)>2):
delta = str(randint(10, 99))
x = list(delta)
if (len(delta)<2):
s[300]='0'
s[301]=x[0]
else:
s[300]=x[0]
s[301]=x[1]
print ' ---> ' + s[300] + s[301]
fb.write("".join(s))
else:
fb.write(line)
fa.close()
fb.close()

No comments:

Post a Comment