[Tutor] how to clear contents of a file

Alan Gauld alan.gauld at btinternet.com
Wed Feb 10 09:50:26 CET 2010

"sudhir prasad" <sudheer.kay at gmail.com> wrote

> how to clear contents of a file with out actually deleting it,

reopening it for write will, clear the contents.

> basically wat im trying to do is copy a source file into  a common file 
> ,run
> the common file,after that  i need to copy another source file  into the
> common file,i ant to clear the  contents of the common file before 
> copying

This is such a bizarre thing to do that I have to ask why you are doing it?
There are so many ways to execute a piece of source code from
within a python program why on earth are you creating a new file to do so?
There may be a valid reason but I can't think of one. If you describe the
wider problem we may be able to offer an alternative solution that
does not require you to copy the code at all.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list