Joey C. wrote:
the issue with the
temporary file is that when I write something new to it, if the old
contents of the file was larger, not all of it will be overwritten.
Not if you open it with
f = open(filename, "w")
which will delete any previous contents the file
may have had.
--
Greg Ewing, C
Joey C. wrote:
To reply to many of your messages (I'm using Google right now due to
lack of a better newsreader at the moment), the issue with the
temporary file is that when I write something new to it, if the old
contents of the file was larger, not all of it will be overwritten.
That's not likel
To reply to many of your messages (I'm using Google right now due to
lack of a better newsreader at the moment), the issue with the
temporary file is that when I write something new to it, if the old
contents of the file was larger, not all of it will be overwritten.
So, the truncate() method will
[EMAIL PROTECTED] wrote:
In short, how might I go about deleting just the contents of a file?
File objects have a truncate() method which chops the file
back to zero length (or a length that you specify).
But why not just delete the file? You can always
create another one with the same name later i
--- John Ridley <[EMAIL PROTECTED]> blurted:
> 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
Apologies - this is, of course, nonsense.
Time for me to hi
[EMAIL PROTECTED] said unto the world upon 2005-04-04 19:39:
I want the "engine" to read the file, write its contents to another
temporary file (for now it just writes the contents; later it will
format it before writing the contents) and then deletes the *contents*
of the temporary file after pri
--- [EMAIL PROTECTED] 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
# [EMAIL PROTECTED] / 2005-04-04 16:39:27 -0700:
> 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.
fd = open("your-file")
fd.truncate()
fd.close()
or open("your-file", "w").close()
--
How