os.tempnam() ignores dir

Randall Hopper aa8vb at yahoo.com
Tue Aug 13 13:28:52 CEST 2002

itsy bitsy meowbot:
 |Randall Hopper wrote:
 |>     >>> print os.tempnam( '/home/rhh', 'prefix' )
 |>     /usr/tmp/prefiCAAa0MMvw
 |> Is this a bug?  I don't see any caveat in the docs about Python ignoring
 |> the dir argument.
 |It's not really a Python bug.  os.tempnam relies on the system's
 |underlying tempnam() function, which varies from platform to platform
 |and can do weird things to the path argument.
 |In a typical Unix, it will do something like the following:
 |- TMPDIR defined in the environment: use that for the path.
 |- path not specified or specified path doesn't exist: punt to the default
 |  coded into in stdio.h.
 |- all else fails: use /tmp

Thanks for the clarification.  The above matches the behavior I'm seeing here.

I'll use Python to unset TMPDIR before calling Python's tempnam so it
will work as advertised.


Randall Hopper
aa8vb at yahoo.com

More information about the Python-list mailing list