Extended print Statement

One of the last and more argumentative additions to Python 2.0 is the extended print statement. The change, which employs a pair of “greater than” symbols (>>), allows you to direct the output of print to a file other than standard output.

In the example below, we utilize our import of sys.stderr to err above:

>>> print >> err, "using sys.stderr again"
using sys.stderr again

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.