NamedTemporaryFile does not match documentation

Discussion in 'Python' started by Jason Friedman, Feb 21, 2013.

  1. Python 3.2.2 (default, Feb 14 2012, 08:06:31)
    [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from tempfile import NamedTemporaryFile
    >>> f = NamedTemporaryFile(delete=False)
    >>> f

    <tempfile._TemporaryFileWrapper object at 0x7f867e8bc050>
    >>> f.name

    '/tmp/tmpqxnd_4'
    >>> f.write("Hello World!\n")

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: 'str' does not support the buffer interface

    Or, maybe I am reading the documentation incorrectly. My goal is to
    be able to write to that temporary file along the lines of "f.write()"
    or "with open(f) as writer ...".
     
    Jason Friedman, Feb 21, 2013
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    793
  2. Victor
    Replies:
    2
    Views:
    796
    Victor
    May 17, 2004
  3. Replies:
    0
    Views:
    634
  4. Lee Harr
    Replies:
    5
    Views:
    878
    Tim Peters
    Dec 30, 2005
  5. Jason Lunz

    monkeypatching NamedTemporaryFile

    Jason Lunz, May 26, 2006, in forum: Python
    Replies:
    2
    Views:
    401
    Jason Lunz
    May 27, 2006
  6. Imbaud Pierre

    tempfile.NamedTemporaryFile wont work

    Imbaud Pierre, Nov 19, 2006, in forum: Python
    Replies:
    6
    Views:
    546
    Imbaud Pierre
    Nov 19, 2006
  7. Replies:
    2
    Views:
    684
    Lawrence D'Oliveiro
    Jul 17, 2008
  8. Roy Smith
    Replies:
    1
    Views:
    720
    Alice Bevan–McGregor
    Dec 31, 2010
Loading...