469,275 Members | 1,871 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

read() on tempfile

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+'
Jul 18 '05 #1
2 1849

"cherico" <ch*****@bonbon.net> wrote in message
news:af**************************@posting.google.c om...
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

Jul 18 '05 #2
cherico wrote:
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.

--
268. If any one hire an ox for threshing, the amount of the hire is
twenty ka of corn.
-- 1780 BC, Hammurabi, Code of Law
--
PrePEP: Builtin path type
http://people.nl.linux.org/~gerrit/c.../pep-xxxx.html
Asperger's Syndrome - a personal approach:
http://people.nl.linux.org/~gerrit/english/

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Thomas Guettler | last post: by
2 posts views Thread by marco | last post: by
1 post views Thread by Matt Garman | last post: by
reply views Thread by Leo Breebaart | last post: by
reply views Thread by Colin Wildsmith | last post: by
6 posts views Thread by Imbaud Pierre | last post: by
6 posts views Thread by James T. Dennis | last post: by
9 posts views Thread by billiejoex | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.