Package grizzled :: Package io :: Class MultiWriter
[frames] | no frames]

Class MultiWriter

object --+
         |
        MultiWriter

Wraps multiple file-like objects so that they all may be written at once. For example, the following code arranges to have anything written to sys.stdout go to sys.stdout and to a temporary file:

import sys
from grizzled.io import MultiWriter

sys.stdout = MultiWriter(sys.__stdout__, open('/tmp/log', 'w'))
Instance Methods
 
__init__(self, *args)
Create a new MultiWriter object to wrap one or more file-like objects.
 
write(self, buf)
Write the specified buffer to the wrapped files.
 
flush(self)
Force a flush.
 
close(self)
Close all contained files.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties

Inherited from object: __class__

Method Details

__init__(self, *args)
(Constructor)

 
Create a new MultiWriter object to wrap one or more file-like objects.
Parameters:
  • args (iterable) - One or more file-like objects to wrap
Overrides: object.__init__

write(self, buf)

 
Write the specified buffer to the wrapped files.
Parameters:
  • buf (str or bytes) - buffer to write