python command line input code example
Example 1: pass argument to a py file
import sys
def hello(a,b):
print "hello and that's your sum:", a + b
if __name__ == "__main__":
a = int(sys.argv[1])
b = int(sys.argv[2])
hello(a, b)
Example 2: python read arguments
import sys
print('Number of arguments:', len(sys.argv), 'arguments.')
print('Argument List:', str(sys.argv))
Example 3: input command in python shell
x = input("Input Your Name")
print(x)
Example 4: read argument from terminal
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Example 5: input from terminal python
text = raw_input("prompt")
text = input("prompt")
Example 6: inpuit inf terfminal ppython
userInput = input("This is a prompt for the input")
print userInput