/dev/null as a file-like object, or logging to nothing

david david at nospam.spam
Tue Sep 11 06:58:24 EDT 2007


Lawrence D'Oliveiro wrote:
> In message <uxv*tevUr at news.chiark.greenend.org.uk>, Sion Arrowsmith wrote:
> 
>> Torsten Bronger  <bronger at physik.rwth-aachen.de> wrote:
>>> Marc 'BlackJack' Rintsch writes:
>>>> `os.devnull`?
>>> Yes, but I wasn't really sure how portable it is, in particular, on
>>> Windows.
>> Windows has a NUL: device which behaves like /dev/null .
> 
> It's not a device, it's a reserved file name. Or rather, a reserved file
> name prefix: any attempt to open a file name beginning with NUL, e.g.
> NUL.DAT, will cause your output to disappear into a black hole.
> 
> This has bitten Windows users more than once.

copy myfile to NULL
copy myfile to NULfilename
copy myfile to NULprefix.txt

All work correctly creating files.

"Prefix" and "beginning with" are a bit misleading,
only a problem with file name NUL(.extension) (not
case sensitive unless case sensitive property is
enabled)

Not sure why you are calling it a reserved file name
instead of device, did not used to be, but many years
since I looked. Of course 'reserved file name' is a
bit misleading: you wouldn't copy bits to a reserved
file name.

Note NUL device used to be very very slow, again,
years since I looked.




More information about the Python-list mailing list