'Store console's output to a variable on each line

I have a function that prints some output, I want to store the console output line-by-line and send it to the user in real-time (until the word Downloaded from sys.stdout.write("Downloaded") printed on console).
I've done the following but don't know why it gaves me error and if there's a better way:

for line in sys.stdout.readlines():
    MyMessage.edit(line)
        # just to mention that I've tried both readlines and splitlines.
        if sys.stdout.read().splitlines() == 'Downloaded':
            break

The error:

for line in stdout.read().splitlines():
io.UnsupportedOperation: not readable


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source