Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, command line argument parsing

How do you accept/parse command line arguments for a py file that has no class? Here is what I have inside my file test.py:

import sys

if __name__ == '__main__':

How do I get the arguments when the file is executed via command line? I call it via:

python test.py <arg1>

and obviously want the value of "arg1".

like image 259
CODe Avatar asked Oct 21 '11 23:10

CODe


1 Answers

Look no further than sys.argv, which is a list containing all arguments passed to the program.

like image 56
jathanism Avatar answered Oct 01 '22 22:10

jathanism