Python 3: receive user input including newline characters Python 3: receive user input including newline characters python-3.x python-3.x

Python 3: receive user input including newline characters


You can import sys and use the methods on sys.stdin for example:

text = sys.stdin.read()

or:

lines = sys.stdin.readlines()

or:

for line in sys.stdin:    # Do something with line.


if you are passing the text into your script as a file , you can use readlines()

eg

data=open("file").readlines()

or you can use fileinput

import fileinputfor line in fileinput.input():    print line