Python printing inline with a sleep command
Question: Why is the following code

    
    
    from __future__ import print_function
    from time import sleep
    
    def print_inline():
        print("Hello ", end='')
        sleep(5)
        print("World")
    
    print_inline()
    

waits until the sleep is done to print `Hello World`, shouldn't print `Hello`
then wait for 5 seconds and print `World` in the same line?


Answer: No, it shouldn't. "Hello" sits in the output buffer until there's a reason to
flush it to the output device. In this case, that "reason" is the end of the
program. If you want The delayed effect, add

    
    
    import sys
    sys.stdout.flush()
    

just before your sleep statement.

See also a more complete discussion
[here](http://stackoverflow.com/questions/230751/how-to-flush-output-of-
python-print).

