Created
January 3, 2025 17:26
-
-
Save simonLeary42/d489f7d01fd95e3b68125590f755e0b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from contextlib import redirect_stdout | |
def stdout2str(lambda_func): | |
read_fd, write_fd = os.pipe() | |
with os.fdopen(write_fd, "w") as write_pipe: | |
with redirect_stdout(write_pipe): | |
lambda_func() | |
with os.fdopen(read_fd, "r") as read_pipe: | |
return read_pipe.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment