replacing single line of text

saad82 at gmail.com saad82 at gmail.com
Fri Jul 28 18:46:50 EDT 2006


I want to be able to replace a single line in a large text file
(several hundred MB). Using the cookbook's method (below) works but I
think the replace fxn chokes on such a large chunk of text. For now, I
simply want to replace the 1st line (CSV header) in the file but I'd
also like to know a more general solution for any line in the file.
There's got a be quick and dirty (and cheap) way to do this... any
help?

Cookbook's method:
output_file.write(input_file.read().replace(stext, rtext))

Thanks,
Pythonner




More information about the Python-list mailing list