Objective
Create a Python program that captures what is printed with print inside a with block, using an io.StringIO object from the io module as destination.
Instructions
- Read an integer
nand thennlines of text (read them all before thewithblock). - Inside a
withblock withredirect_stdout(buffer)(from thecontextlibmodule), print each line in uppercase. - Outside the block, get the captured text with
buffer.getvalue()and showCaptured lines: k,Characters: kand then each captured line preceded by"> ".
3
hola
mundo
x y
Captured lines: 3
Characters: 15
> HOLA
> MUNDO
> X Y
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise