I'm new to using pipes and I/O in python, and I've been using
sys.stdin.readlines() from a file.
How do you read in an additional argument? For example:
more input.txt | python program.py 200
I want to store that '200' in as a variable (int) in my program to use.
number = int(sys.argv)
For testing purposes I just typed
but I didn't get the '200'.
I have two files, 'test.txt' and 'test.py'
#!/usr/bin/python import sys line = "" for n in [line for line in sys.stdin.readlines()]: print n
$ more test.txt | python test.py
it will print out
asdfsdf 200 sldkfjs 100 kljslkd 300
My goal is to just print out the line with the number I pass as an argument
#!/usr/bin/python import sys number = int(sys.argv) line = "" for n in [line for line in sys.stdin.readlines()]: if n.split() == number: print n
n.split() should be the number from every line in the file correct? When running
$ more test.txt | python test.py 200
What I want to return is:
But instead it's blank...