Burgerlib Python
Loading...
Searching...
No Matches
burger.Interceptstdout Class Reference

Handy class for capturing stdout from tools and python itself. More...

Inheritance diagram for burger.Interceptstdout:
Collaboration diagram for burger.Interceptstdout:

Public Member Functions

 __init__ (self)
 Declares the internal variables.
 __enter__ (self)
 Invoked on "with" which intercepts all future stdout.
 __exit__ (self, *args)
 Disconnect the stdout and store the items into a list of lines.

Protected Attributes

 _stdout = None
 Saved copy of sys.stdout.
 _stringio = None
 StringIO to redirect output to.

Detailed Description

Handy class for capturing stdout from tools and python itself.

Examples

# Import the class
from burger import Interceptstdout
# Instanciate the class, which intercepts stdout

with Interceptstdout() as output: do_somethingthatprints()

print("capture me!")
# Once out of scope, output has a list of strings
# of the captured stdout output.
print(output)

Member Function Documentation

◆ __exit__()

burger.Interceptstdout.__exit__ ( self,
* args )

Disconnect the stdout and store the items into a list of lines.

Using splitlines(), output the buffer into a list of lines into the output field.