Skip to content

Instantly share code, notes, and snippets.

@simonLeary42
Created January 3, 2025 17:26
Show Gist options
  • Save simonLeary42/d489f7d01fd95e3b68125590f755e0b3 to your computer and use it in GitHub Desktop.
Save simonLeary42/d489f7d01fd95e3b68125590f755e0b3 to your computer and use it in GitHub Desktop.
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