writing on file not until the end
Peter Otten
__peter__ at web.de
Mon May 25 04:52:30 EDT 2009
Alessandro wrote:
> - until now, the only solution which works is to repeat the code while
> the file is still open, which means a quite redundant code:
>
> linestring = open(path, 'r').read()
> 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)
>
> linestring = open(path, 'r').read()
> 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)
Is this the complete script? The only effect of the second copy of your code
above is that it implicitly closes the first Nfile. Otherwise it is cargo
cult.
Peter
More information about the Python-list
mailing list