1import sys
2print("This is the name of the script:", sys.argv[0])
3print("Number of arguments:", len(sys.argv))
4print("The arguments are:" , str(sys.argv))
5
6#Example output
7#This is the name of the script: sysargv.py
8#Number of arguments in: 3
9#The arguments are: ['sysargv.py', 'arg1', 'arg2']
1import sys
2
3def hello(a,b):
4 print "hello and that's your sum:", a + b
5
6if __name__ == "__main__":
7 a = int(sys.argv[1])
8 b = int(sys.argv[2])
9 hello(a, b)
10# If you type : py main.py 1 5
11# It should give you "hello and that's your sum:6"
1#!/usr/bin/python
2
3import sys
4
5print 'Number of arguments:', len(sys.argv), 'arguments.'
6print 'Argument List:', str(sys.argv)
7
8#Terminal
9# $ python test.py arg1 arg2 arg3
10
11#print
12#Number of arguments: 4 arguments.
13#Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
14
15
1#!/usr/bin/python
2
3import sys
4
5print('Number of arguments:', len(sys.argv), 'arguments.')
6print('Argument List:', str(sys.argv))