I'm working on a python 3 project that does the exact same thing as bash's 'wc' (Word count) command. The format for input looks like this:
$ python3 myWC.py < fileName.txt
I'd like to use the file given to count over the bytes, words, and lines in the file and print them. I've tried using stdin but even simple print() statements seem to be printing stdin's object instead of the actual string given. Could someone give me some guidance on basic stdin usability in Python 3? Thank you!
As pointed out below, I was using '>' instead of '<'. But now when I run this code:
import sys
def main():
word = sys.stdin.readline()
print(word)
main()
I simply get a blank line as output in Terminal
Expanding on my comment above, I would say the following code would do the trick (NOTE: this is not Python 3, but Python 2.7. Some quick Googling told me they are similar in this however).
In echo.py:
import sys
print sys.stdin.read()
Then in your terminal call it like this:
python echo.py < test.txt
This should echo the contents of test.txt on your terminal.