[Tutor] tempfile and passing files around
Gabriel Farrell
gsf at panix.com
Tue Jul 11 20:48:33 CEST 2006
I have an issue with the tempfile module that I can't figure out.
Snippet of relevant script looks like so:
1 bob = tempfile.NamedTemporaryFile()
2 bob.write('Hallo!')
3 bob.read()
4 sam = tempfile.NamedTemporaryFile()
5 bobHandle = file(bob.name)
6 bobHandle.read()
As you can see, I'm creating two NamedTemporaryFiles and then reading
from the first. Line 3 doesn't really do anything, there's no output
because we're reading at the end of the file, but as long as I leave
it in, line 6 will output the expected 'Hallo!'. If I remove it,
there's no output from line 6.
I really stumbled upon this, and it looks like, if you create a
tempfile and write to it, then create another tempfile, you can only
open up the first to read it again if you do a read method on the
first file before you open it. I dunno, just kinda baffled.
TIA, gabe
More information about the Tutor
mailing list