read() on tempfile

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cherico

    read() on tempfile

    from tempfile import *

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

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

    #2
    Re: read() on tempfile


    "cherico" <cherico@bonbon .net> wrote in message
    news:afc115ec.0 401291041.155b5 1ee@posting.goo gle.com...[color=blue]
    > from tempfile import *
    >
    > f = NamedTemporaryF ile ()
    > f = write ( 'test' )
    > print f.read () #here print nothing
    >
    > why is it nothing to read()?
    > I suppose f is of mode 'w+'[/color]

    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



    Comment

    • Gerrit Holl

      #3
      Re: read() on tempfile

      cherico wrote:[color=blue]
      > from tempfile import *
      >
      > f = NamedTemporaryF ile ()
      > f = write ( 'test' )
      > print f.read () #here print nothing[/color]

      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

      Asperger's Syndrome - a personal approach:


      Comment

      Working...