Richard D. Moores wrote:
But that makes me wonder if there isn't a simpler way to do it with
Python -- to delete the contents of a file without deleting the file?
Opening a file for writing will flush the contents.
open(filename, 'w')
will do it, taking advantage of Python's garbage collector to
(eventually) close the file. The more careful way is hardly any harder:
open(filename, 'w').close()
and this ensures that the file isn't left open any longer than necessary.
--
Steven
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor