How to read/process command line arguments?

后端 未结 17 2058
离开以前
离开以前 2020-11-21 05:14

I am originally a C programmer. I have seen numerous tricks and \"hacks\" to read many different arguments.

What are some of the ways Python programmers can do this

17条回答
  •  误落风尘
    2020-11-21 05:28

    One way to do it is using sys.argv. This will print the script name as the first argument and all the other parameters that you pass to it.

    import sys
    
    for arg in sys.argv:
        print arg
    

提交回复
热议问题