problems using pythom tempfile module

buffi bjorn.kempen at gmail.com
Sat Sep 15 18:41:49 EDT 2007


Pretend that you have a number that is always pointing somewhere in
your temporary file.
It starts a 0.
If you then write "lalalala" (8 characters) it will point after these
at position 8, so that you can write more stuff after your previous
text later by calling write.

The read method reads all the data from the current position of the
"pointer" to the end of the file. If you simply call it after writing,
you wont get anything since you are already at the end of the file.
Therefore you "rewind" the pointer back to the start by calling seek
which takes the position in the file to go to...
your_file.seek(0) returns you to the start of the file to read all of
its data

- Björn Kempén




More information about the Python-list mailing list