I have this code:
line = input("Line of code: ")
output = exec(line)
Naturally it doesn't work because if you write print("Hello World")
it only prints "Hello World" and the output
variable will have None value.
So, in PHP I could use the output buffering in this way:
<?php
ob_start();
echo "Hello World";
output = ob_get_clean();
?>
Is there an equivalent function or a similar way in Python? This is exactly what I need. Thanks in advance.