I used it when changing the process with the argument passed when executing the script
OS: Windows7 Language: Python 2.7.10
ʻImport sys to get the arguments stored in the array of
sys.argv`
test.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
if __name__ == "__main__":
count = 0
for roop in sys.argv:
print str(count) + 'Second argument: ' + str(roop)
count += 1
python test.py aiu e o 1 23
0th argument: test.py
1st argument: aiu
Second argument: e
Third argument: o
4th argument: 1
5th argument: 23
Recommended Posts