Super Newbie Question

John Ridley ojokimu at yahoo.co.uk
Mon Apr 4 20:03:56 EDT 2005


--- joeyjwc at gmail.com wrote:

> In short, how might I go about deleting just the contents of a file?
> I tried several methods with my limited knowledge but had no luck.

I suppose the simplest thing to do would be to write an empty string to
the file:

>>> f = open('tmpfile.txt', 'w')
>>> f.write('')
>>> f.close()   # or f.flush(), if keeping open

HTH

 

John Ridley

Send instant messages to your online friends http://uk.messenger.yahoo.com 



More information about the Python-list mailing list