os.tempnam() ignores dir

itsy bitsy meowbot 53ab2750 at meowing.net
Mon Aug 12 16:54:33 EDT 2002

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

Under native Windows, you gneerally have the temp directories defined
in the environment.  Under cygwin, behavior is (of course) more Unixy.

More information about the Python-list mailing list