Program arguments

A program can be passed arguments from the command line.

Input:

source_code/appendix_c_python/example14_arguments.py
#Import the system library in order to use the argument list.
import sys

print 'The number of the arguments given is', len(sys.argv),'arguments.'
print 'The argument list is ', sys.argv, '.'

Output:

$ python example14_arguments.py arg1 110
The number of the arguments given is 3 arguments.
The argument list is  ['example14_arguments.py', 'arg1', '110'] .
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset