carputils
Doxygen code documentation for the python framework controlling openCARP
Classes | Functions
carputils.stream Namespace Reference

Classes

class  DummyStream
 A placeholder stream that simply ignores the write instruction. More...
 
class  MultiStream
 A stream that forwards on the write call to other streams. More...
 
class  RegexCallbackStream
 

Functions

def merge (streams)
 Merge the provided streams into a single one. More...
 
def divert_std (replacement)
 Context manager to temporarily replace sys.stdout and sys.stderr. More...
 

Function Documentation

◆ divert_std()

def carputils.stream.divert_std (   replacement)

Context manager to temporarily replace sys.stdout and sys.stderr.

Either create a file object:

>>> out = open('somefile.txt', 'r')

or create a string stream:

>>> from cStringIO import StringIO
>>> out = StringIO()

and then use thus context manager to ensure that all stdout and stderr gets written to the desired output:

>>> with divert_stdout(out):
>>> print 'Hello, world!'
Parameters
replacementstring stream Replacement string stream object - in practice, anything with a write
method

◆ merge()

def carputils.stream.merge (   streams)

Merge the provided streams into a single one.