Friday, 5 January 2018

Command Line Arguments

#!/usr/bin/python3
import sys
print ('Number of arguments:', len(sys.argv), 'arguments.')
print ('Argument List:', str(sys.argv))

Now run the above script as follows −
$ python test.py arg1 arg2 arg3

This produces the following result-
Number of arguments: 4 arguments.
Argument List: ['test.py', 'arg1', 'arg2', 'arg3']


No comments:

Post a Comment

Lists

Python  Lists Python Collections (Arrays) There are four collection data types in the Python programming language: List  is a ...