Answers for "python get text that is already printed"

0

python get text that is already printed

import sys
import io

old_stdout = sys.stdout # Memorize the default stdout stream
sys.stdout = buffer = io.StringIO()

print('123')
a = 'HeLLo WorLd!'
print(a)
# Call your algorithm function.
# etc...

sys.stdout = old_stdout # Put the old stream back in place

whatWasPrinted = buffer.getvalue() # Return a str containing the entire contents of the buffer.
print(whatWasPrinted) # Why not to print it?
print(123)
Posted by: Guest on April-16-2022

Code answers related to "python get text that is already printed"

Python Answers by Framework

Browse Popular Code Answers by Language