Jeremy Hunts
Jeremy Hunts

Reputation: 363

python sys.stdin.read not working

This is my code

if __name__ == '__main__':

    import sys
    text = sys.stdin.read().decode('ascii', errors='replace')
    print text

When I run it, I enter the text and press enter, but nothing happens and it keeps running forever. What is wrong ?

Upvotes: 0

Views: 4826

Answers (2)

Tayyab Chaudhary
Tayyab Chaudhary

Reputation: 468

You should enter the text, press the Enter key, then press Ctrl + Z. It will give the correct result.

For more help, please visit this: https://bugs.python.org/issue5505

Upvotes: 0

Flint
Flint

Reputation: 1691

  • Flush the standard input with Ctrl+d
  • alternatively use input() or raw_input()
  • check the docs >>> help(sys.stdin.read)

Upvotes: 2

Related Questions