Output Utils
GitHub Link to Code.
Output utilities for suppressing print statements.
Provides utility methods for controlling stdout behavior.
- class mdxplain.utils.output_utils.OutputUtils
Utility class for output management operations.
Provides static methods for controlling stdout behavior, such as suppressing print output in specific code blocks.
Examples
>>> from mdxplain.utils.output_utils import OutputUtils >>> with OutputUtils.suppress_output(): ... print("This will not be shown") >>> print("This will be shown") This will be shown
- static suppress_output()
Context manager to suppress all print output.
Redirects stdout to a null buffer, effectively silencing all print statements within the context. Automatically restores original stdout even if exceptions occur within the context block.
Yields
- None
Context manager that temporarily redirects stdout
Examples
>>> from mdxplain.utils.output_utils import OutputUtils >>> with OutputUtils.suppress_output(): ... print("This will not be shown") ... some_function_with_prints() >>> print("This will be shown") This will be shown
Notes
This only suppresses stdout (print statements). stderr output (warnings, errors) will still be visible. The original stdout is guaranteed to be restored even if an exception occurs within the context block due to the try/finally pattern.