How to get a string from a command line argument in python. This time, I will describe how to import the sys module.
You can read standard input with sys.argv. For the time being, I also added error handling, so please refer to it. In this case, params [0] is the execution command (py file).
import sys
## get form params ##
params = sys.argv
length = len(params)
if (length != 2):
print 'Usage: python %s parameter' % params[0]
quit()
Change length and quit () accordingly. After that, store the value read from the standard input as follows and use it.
value = params[1]
Recommended Posts