[Python-Dev] Special file "nul" in Windows and os.stat

"Martin v. Löwis" martin at v.loewis.de
Wed Nov 7 10:33:54 CET 2007


> Perhaps a note should be added to the docs that the 'existence' of 'nul', 
> etc, is inconsistent in Windows and hence, at present, in Python.

That is a statement that I want to get better confirmation on also.
What is the precise condition where Windows (or perhaps just Python?)
would claim that nul exists?

> In part, it seems to me, that anyone doing Windows-specific stuff should 
> decide for themselves whether 'nul' exists for their purposes or not. 

No. The intention of os.path.exists clearly is that if it says that it
exists, there is a high chance that you can subsequently open it, and
vice versa. Of course, there are other issues, such as timing and
permissions, but in general, Python applications should not have to
"bypass" the standard library with platform-specific knowledge.

It's somewhat unfortunate that os.path.exists() is implemented on top
of stat(2), which does much more than finding out whether the file
exists. Alas, it is the POSIX tradition that this "ought" to work, so
this strategy is just a fact of life.

I don't know what the actual use case is for testing "existence" of
"nul", but I guess a "natural" problem is that the user says she
wants to create a file named "nul", and the application checks whether
this is a new file name, which it isn't (it exists in every directory,
if I understand correctly).

Regards,
Martin



More information about the Python-Dev mailing list