I'm new to programming. I looked at tutorials for this, but I'm just getting more confused. But what I'm trying to do is use stdin and stdout to take in data, pass it through arguments and print out output results.
So basically,on the command line, the user will input the and an argument.
The arguments are:
i = sys.argv [1]
f = sys.argv [2]
w = sys.argv [3]
Then using if/else the program will execute some stuff based on which argument chosen above.
i.e: On the command line the user will enter the script name and f (for sys.argv[2:2])
$ test.py f
.
if sys.argv == i:
#execute some stuff
elif sys.argv == f:
#execute some stuff
else:
sys.argv == w
#execute some stuff
With stdin/stdout how can I create this switch where the program executes one piece of the code based on which argv is chosen? Any input will be greatly appreciated.
sys.argvis a list of command-line parameters and not the same thing as stdin/stdout, which are pseudo files. Reading from stdin usesraw_input()in Python 2, in Python 3 useinput().