hello; I need help in append a data in new file. the problem is the new data are generated in every run. so at the end I should get all the changes in one file (means for all running) if I run 2 times so should get couple of data set. note all outputs in txt file. ex: this is the first run data 1.0362 1.015 1.011 0.9948 1.0024 0.9936 0.9129 0.9184 0.9868 0.9682 0.975 0.8953 1.0627 1.0517 1.0306 1.0387 1.0501 1.0485 1.0467 1.0342 1.0389 1.0109 1.0107 1.0066
next run the data changes in the same output file 1.020 1.043 1.111 0.343 1.454 1.999 0.9129 0.9184 0.9868 0.9682 0.975 0.8953 1.0555 1.2222 1.333 1.4444 1.2222 1.2222 1.1111 1.1111 1.1111 1.1111 1.1111 1.1111 the appended file should be 1.0362 1.015 1.011 0.9948 1.0024 0.9936 0.9129 0.9184 0.9868 0.9682 0.975 0.8953 1.0627 1.0517 1.0306 1.0387 1.0501 1.0485 1.0467 1.0342 1.0389 1.0109 1.0107 1.0066 1.020 1.043 1.111 0.343 1.454 1.999 0.9129 0.9184 0.9868 0.9682 0.975 0.8953 1.0555 1.2222 1.333 1.4444 1.2222 1.2222 1.1111 1.1111 1.1111 1.1111 1.1111 1.1111 more run more data will generate. I tried so many times without any result. t=open('old data'.txt') d=open('new data.txt','w') while True: line=t.readline() if len(line) ==0: break volt=line.split() volt=map(float, volt) for i in range (len(line.split())): d.write(str(volt[i])+' ') d.write('\n') d.close but this only bring as same as the old file. also I found some codes from the committee and tried but still not working. import sys def check_dup(fd1): print fd1 fd1.seek(0,0) list1=[] while not done: x = fd1.readline() if x == "": break else: list1.append(x) return list1 fname = 'new data.txt' fd = open(fname,'a+') print fd t=open('old data'.txt' while not done: while True: line=t.readline() if len(line) ==0: break volt=line.split() volt=map(float, volt) for i in range (len(line.split())): print str flag = check_dup(fd) print flag fd.seek(0,2) fd.write(str(volt[i]) + ' ') fd.write('\n') break looking forward for prompt response, best regards, Ahmed Naufal
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor