portable /dev/null again

Skip Montanaro skip at pobox.com
Wed Mar 24 15:12:33 EST 2004


    John>      class nullFile:
    John>          def write(self, data):
    John>              pass

    John> However, as the above does not present a full Python file object,
    John> it can't go everywhere that say, sys.stdout can go.  

How about:

    class nullFile:
        def _null(self, *args, **kwds):
            pass

        def __getattr__(self, name):
            return self._null

?

Skip




More information about the Python-list mailing list