Answers for "command line arguments python app"

11

read argument from terminal

#!/usr/bin/python

import sys

print 'Number of arguments:', len(sys.argv), 'arguments.'
print 'Argument List:', str(sys.argv)

#Terminal
# $ python test.py arg1 arg2 arg3

#print
#Number of arguments: 4 arguments.
#Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
Posted by: Guest on May-22-2020
0

how to take list as command line arguments in python

>>> input = "[2,3,4,5]"
>>> map(float, input.strip('[]').split(','))
[2.0, 3.0, 4.0, 5.0]
>>> A = map(float, input.strip('[]').split(','))
>>> print(A, type(A))
([2.0, 3.0, 4.0, 5.0], <type 'list'>)
Posted by: Guest on November-19-2020

Code answers related to "command line arguments python app"

Python Answers by Framework

Browse Popular Code Answers by Language