[Tutor] Displaying Status on the Command Line

Zachary Ware zachary.ware+pytut at gmail.com
Thu Nov 8 10:36:53 EST 2018


On Thu, Nov 8, 2018 at 4:12 AM Chip Wachob <wachobc at gmail.com> wrote:
> I should have mentioned that I'm working with Python 2, but I think I
> can parse my way through these examples.

You can use any of the `print` function tricks above in Python 2 with
the following boilerplate:

from __future__ import print_function

import sys

_orig_print = print

def print(*args, **kwargs):
    flush = kwargs.pop('flush', False)
    _orig_print(*args, **kwargs)
    if flush:
        file = kwargs.get('file', sys.stdout)
        file.flush()

When you get to upgrade to Python 3, just throw the above code away
and things will work just the same :)

--
Zach


More information about the Tutor mailing list