read() on tempfile

C

cherico

from tempfile import *

f = NamedTemporaryFile ()
f = write ( 'test' )
print f.read () #here print nothing

why is it nothing to read()?
I suppose f is of mode 'w+'
 
S

Sidharth Kuruvila

cherico said:
from tempfile import *

f = NamedTemporaryFile ()
f = write ( 'test' )
print f.read () #here print nothing

why is it nothing to read()?
I suppose f is of mode 'w+'

the rpoblem is probably that your file pointer is sitting at the end of the
file after you write something
try f.seek(0) before you read, might work
 
G

Gerrit Holl

cherico said:
from tempfile import *

f = NamedTemporaryFile ()
f = write ( 'test' )
print f.read () #here print nothing

Strange, it should raise an Exception.
I guess you typed it over?

'write' should give a NameError. You want to do f.write, not f=write.
After that, you first want to seek to 0.

Gerrit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top