command line input in python 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: python argument command line
import sys
print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)
Example 4: input code for python
txt = raw_input("Type something to test this out: ")
print "Is this what you just said?", txt
Example 5: how to get input in python3
test_text = input ("Enter a number: ")
test_number = int(test_text)
print ("The number you entered is: ", test_number)