This does not work for databricks runtime 11.0.
Code:
from IPython.utils.capture import CapturedIO
import sys
capture = CapturedIO(sys.stdout, sys.stderr)
print("asdfghjkjhgf")
cmem = capture.stdout
print(cmem)
Output:
asdfghjkjhgf
AttributeError: 'OutStream' object has no attribute 'getvalue'