[Python-Dev] unifying os.rename semantics across platform

skip@pobox.com (Skip Montanaro) skip@pobox.com (Skip Montanaro)
Tue, 22 May 2001 16:54:42 -0500

Couldn't figure out why this message never generated any comment.  Turns out
it didn't reach the list because the host I sent it from
(dynamic4.tttech.com) couldn't be resolved.  I just noticed it in my errors
mailbox and am sending it out again.

It was brought to my attention a week ago by a client that os.rename
semantics differ between Unix and Windows.  On Unix, if the destination file
already exists it is silently deleted.  On Windows, an exception is raised.
I was able to verify this for Python 2.0 on Windows98.  I assume nothing
changed for 2.1, but I can't verify that.  (Windows trashed my partition
table and my Linux root partition while I was downloading 2.1.
Consequently, I no longer run Windows.  Take that, Bill...)  I haven't
checked the Mac yet (will do that when I get back to the US), but I think
that os.rename should have the same semantics across all platforms.  To the
extent reasonably possible, I think this should also be true of other common
functions exposed through the os module.

On the (unsupportable) theory that to-date, more Python apps have been
written and/or deployed on Unix-like systems and that where Windows apps are
concerned, many developers will have added a thin wrapper to mimic the Unix
semantics, I think less breakage would result if the Unix semantics were
implemented in the Windows version.  It appears that is what POSIX
compliance would demand as well.