how to switch from os.tmpnam to os.tmpfile

Nick Craig-Wood nick at craig-wood.com
Thu Jun 8 11:30:04 EDT 2006


Harold Fellermann <dadapapa at googlemail.com> wrote:
>  I need to create a temporary file and I need to retrieve the path
>  of that file.  os.tmpnam() would do the job quite well if it wasn't
>  for the RuntimeWarning "tmpnam is a potential security risk to your
>  program". I would like to switch to os.tmpfile() which is supposed
>  to be safer, but I do not know how to get the path information from
>  the file object returned by tmpfile(). any clues?

You can't. The file opened doesn't have a name

    tmpfile(...)
        tmpfile() -> file object
        
        Create a temporary file with no directory entries.

Have a look at the functions in the tempfile module, mkstemp() in
particular (the posix way), or NamedTemporaryFile()

  http://docs.python.org/lib/module-tempfile.html

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list