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

Torsten Bronger bronger at physik.rwth-aachen.de
Sat Sep 8 13:54:18 EDT 2007


Hallöchen!

Carsten Haese writes:

> On Sat, 2007-09-08 at 18:52 +0200, Torsten Bronger wrote:
>
>> Is there a portable and simply way to direct file-like IO to
>> simply nothing?  [...]
>>
>> [...]
>
> This might work:
>
> class LogSink(object):
>     def write(self, *args, **kwargs): pass
>     def flush(self, *args, **kwargs): pass
>
> logging.basicConfig(stream=LogSink())
>
> I haven't tested this thoroughly, so it's possible that there are
> more methods that the stream is expected to implement.

No, write and flush are enough.  Thank, this works.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
                      (See http://ime.webhop.org for ICQ, MSN, etc.)



More information about the Python-list mailing list