Neil Schemenauer wrote:
> On Mon, Mar 17, 2003 at 12:07:44PM -0500, Greg Ward wrote:
>
>>But open() doesn't work that way. open(filename, "wb") unconditionally
>>clobbers filename. That's one way to resolve the race condition, I
>>suppose, but not really satisfactory.
>
>
> os.open with the O_EXCL flag does. Windows probably does things
> differently though so using tempfile is probably best.
For clarification, open(n, 'wb') on Windows python will clobber as well.
I mistakenly assumed that if there were any open read handle on the
file, then the open('wb') would fail. It *will* fail if there is another
open write handle.
Clobbering in Windows can be avoided by using win32file.CreateFile(n,
...., CreationDisposition=win32file.CREATE_NEW). This is in the
(obviously non-cross-platform) Win32 extensions for Python.
+1 on the tempfile investigation!
Cheers,
-- Graham