# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 """General helper utilities the workshop notebooks""" # Python Built-Ins: from io import StringIO import sys import textwrap def print_ww(*args, width: int = 100, **kwargs): """Like print(), but wraps output to `width` characters (default 100)""" buffer = StringIO() try: _stdout = sys.stdout sys.stdout = buffer print(*args, **kwargs) output = buffer.getvalue() finally: sys.stdout = _stdout for line in output.splitlines(): print("\n".join(textwrap.wrap(line, width=width)))