Burgerlib Python
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
burger.Interceptstdout Class Reference

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

Inheritance diagram for burger.Interceptstdout:
Inheritance graph
[legend]
Collaboration diagram for burger.Interceptstdout:
Collaboration graph
[legend]

Public Member Functions

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

Private Attributes

 _stdout
 Saved copy of sys.stdout.
 
 _stringio
 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__()

def 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.