os.tmpfile() vs. tempfile.TemporaryFile()

Discussion in 'Python' started by John Nagle, Nov 11, 2010.

  1. John Nagle

    John Nagle Guest

    Is there any reason to prefer "tempfile.TemporaryFile()"
    over "os.tmpfile()"? Both create a nameless temporary file
    that will be deleted on close.

    John Nagle
     
    John Nagle, Nov 11, 2010
    #1
    1. Advertisements

  2. John Nagle

    Guest

    On Nov 11, 11:32 am, John Nagle <> wrote:
    >    Is there any reason to prefer "tempfile.TemporaryFile()"
    > over "os.tmpfile()"?  Both create a nameless temporary file
    > that will be deleted on close.
    >
    >                                 John Nagle


    tempfile.TemporaryFile has more options, e.g. file prefix, suffix, dir
    location, mode, and buf size. if you don't care about any of that,
    then it probably makes no difference.
     
    , Nov 11, 2010
    #2
    1. Advertisements

  3. John Nagle

    Carl Banks Guest

    On Nov 11, 10:32 am, John Nagle <> wrote:
    >    Is there any reason to prefer "tempfile.TemporaryFile()"
    > over "os.tmpfile()"?  Both create a nameless temporary file
    > that will be deleted on close.


    os.tmpfile calls your OS's tmpfile system call.
    tempfile.TemporaryFile creates the temporary file itself.

    So, if you trust your OS more than Python, use os.tempfile.


    I-only-use-tempfile-module-ly yr's,

    Carl Banks
     
    Carl Banks, Nov 12, 2010
    #3
    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. Oliver Knoll

    reading file created with tmpfile?

    Oliver Knoll, Jul 18, 2003, in forum: C Programming
    Replies:
    4
    Views:
    604
    Chris Torek
    Jul 18, 2003
  2. Harold Fellermann

    how to switch from os.tmpnam to os.tmpfile

    Harold Fellermann, Jun 8, 2006, in forum: Python
    Replies:
    7
    Views:
    1,458
    Nick Craig-Wood
    Jun 8, 2006
  3. John Machin
    Replies:
    4
    Views:
    848
    Dennis Lee Bieber
    Feb 12, 2007
  4. tmpfile and freopen

    , Jun 5, 2006, in forum: C Programming
    Replies:
    1
    Views:
    535
    Barry Schwarz
    Jun 15, 2006
  5. Replies:
    7
    Views:
    545
    Karthik Gurusamy
    Dec 28, 2007
  6. Brad
    Replies:
    0
    Views:
    346
  7. Replies:
    2
    Views:
    487
  8. Alex van der Spek

    Difference between tempfile and spooled tempfile?

    Alex van der Spek, Apr 5, 2012, in forum: Python
    Replies:
    2
    Views:
    548
    Steve Howell
    Apr 5, 2012
Loading...