------------------------------------------------------------------------------
MC logo
Copy Input to Output II
[^] Code Examples
------------------------------------------------------------------------------
<<Copy Input to Output I copy2.py Copy Input to Output III>>
#!/usr/bin/python3

# Script to copy standard input to standard output, one line at a time,
# now using a break.

import sys

# Loop until terminated by the break statement.
while 1:
    # Get the line, exit if none.
    line = sys.stdin.readline()
    if not line:
        break

    # Print the line read.
    print(line[:-1])

This gets around the problem of not being able to assign in the while test and lets you write the loop without repeating the read.
<<Copy Input to Output I Copy Input to Output III>>