On 11Apr2024 14:42, Olivier B. wrote:
I am trying to use StringIO to capture stdout, in code that looks like this:
import sys
from io import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
print( "patate")
mystdout.seek(0)
sys.stdout = old_stdout
print(mystdout.read())
Well
On 4/11/2024 8:42 AM, Olivier B. via Python-list wrote:
I am trying to use StringIO to capture stdout, in code that looks like this:
import sys
from io import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
print( "patate")
mystdout.seek(0)
sys.stdout = old_stdout
print(mystd
Partly answering myself:
For some reason, right after mystdout has been created, i now have to
do mystdout.seek(0) and this solves the issue.
No idea why though..
Le jeu. 11 avr. 2024 à 14:42, Olivier B.
a écrit :
>
> I am trying to use StringIO to capture stdout, in code that looks like this:
I am trying to use StringIO to capture stdout, in code that looks like this:
import sys
from io import StringIO
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
print( "patate")
mystdout.seek(0)
sys.stdout = old_stdout
print(mystdout.read())
Well, it is not exactly like this, since this