[python-win32] Modify only the first line of a big file (Roughly 1.5MB - For thousands of file).

Robert kxroberto at googlemail.com
Sun May 3 13:01:27 CEST 2009


Khalid Moulfi wrote:
> Hi all,
>  
> I have thousands of file and I must update only the first line.
> My concern is : is it possible to read only the first line for each of 
> these files and update the first line only without reading the file 
> completely ?
>  
> Version of Python is 2.2.1
>  
> Thanks for any help,
>  

when the length of the line/initial bytes doesn't change (by means 
of enough balancing spaces or so) you can open the file in "r+" 
mode and overwrite sections; e.g. after reading some bytes/line or 
so do f.seek(0) and overwrite the initial bytes.




More information about the python-win32 mailing list