portable /dev/null again

Jeff Epler jepler at unpythonic.net
Wed Mar 24 19:51:34 CET 2004


I think this is a decent idea, though with only two real platforms
(Unix, win32) it's not hard to implement.  At least, I assume that OSX
has /dev/null...

    if os.name == 'win32':
        nullfilename = 'nul:'
    else:
        nullfilename = '/dev/null
    nullfile = file(nullfilename, "r+b")
note that "nullfile" can be closed just like any other file, which is
likely to lead to problems..  or you could os.close(fileno(nullfile))
too..

Jeff




More information about the Python-list mailing list