On Sun, May 24, 2009 at 2:46 PM, Alexzive <zasaconsult...@gmail.com> wrote:
> Hello, > I am a newby with python. I wrote the following code to extract a text > from a file and write it to another file: > > linestring = open(path, 'r').read() #read all the inp file in > linestring > > i=linestring.index("*NODE") > i=linestring.index("E",i) > e=linestring.index("*",i+10) > textN = linestring[i+2:e-1] # crop the ELement+nodes list > Nfile = open("N.txt", "w") > Nfile.write(textN) > > unfortunately when I check N.txt some lines are missing (it only crop > until "57, 0.231749688431, 0.0405121944142" but I espect the final > line to be "242, 0.2979675, 0.224605896461". I check textN and it has > all the lines until "242..") > > when I try Nfile.write(textN) again it writes some more lines but > still not all! > what is wrong whit this? > > Many thanks for your help! > Alex > > the original file to crop (in path) looks like this: [snip file] I didn't test this, but I would guess you're seeing this because of buffering. Try adding Nfile.flush() to the end.
-- http://mail.python.org/mailman/listinfo/python-list