Reputation: 16782
How do I capture piped text in python. For example something like this
cat foo.py | ./foo.py
in foo.py I have the following:
if __name__ == "__main__":
text = raw_input()
The problem is raw_input()
terminates after the new line. How do I capture the whole thing as a string/list?
Upvotes: 2
Views: 746
Reputation: 28489
raw_input
is just a helper for prompting the user interactively. If you want to read any amount from stdin, use sys.stdin.read()
.
Upvotes: 6