problems using pythom tempfile module

samir.vds at googlemail.com samir.vds at googlemail.com
Sat Sep 15 18:13:54 EDT 2007


On Sep 15, 5:24 pm, buffi <bjorn.kem... at gmail.com> wrote:
> On Sep 15, 11:11 pm, "samir.... at googlemail.com"
>
>
>
> <samir.... at googlemail.com> wrote:
> > Hello everyone,
>
> > I'm trying to test the tempfile module with the following script,
> > which basically creates a temporary file, fills the file with some
> > test data and prints it.
>
> > import tempfile
>
> > t = tempfile.TemporaryFile()
> > t.write("lalalala")
> > t.flush()
> > print t.read()
>
> > Unfortunately, the print statement gives me an empty string. Can
> > somebody tell me what I'm doing wrong ?
>
> > regards Samir
>
> Do a t.seek(0) before you do the read to "rewind" the file and then it
> should work.

Ok, this really worked. Can you elaborate why I have to insert this
statement?




More information about the Python-list mailing list