file IO

Darren Dale dd55 at cornell.edu
Mon Aug 2 20:52:33 EDT 2004


Can anyone explain this?

I have a file called old.dat with two lines:

1
2

So it's 3 bytes long. I run the following:

import os
f = file('old.dat',mode='r')
olddata = f.readlines()
f.close()

f = file('new.dat',mode='w')
f.writelines(olddata)
f.close()

new.dat is now 4 bytes long. ???

I need to reformat and then save some data.   Then I need to be able to 
export the reformatted data to a spreadsheet-friendly format. But once I 
have simply copied (trying to isolate the problem) the file using the 
script above, my export function takes 10x as long as it would have with 
the original file. And worse, the output has an extra newline character 
added at the end of each line. Any suggestions would really be 
appreciated, I am going a bit crazy trying to understand this.

Darren



More information about the Python-list mailing list