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

Lawrence D'Oliveiro ldo at geek-central.gen.new_zealand
Tue Sep 11 02:22:32 CEST 2007


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.



More information about the Python-list mailing list