How to read/process command line arguments?

后端 未结 17 2015
离开以前
离开以前 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:32

    import sys
    
    print("\n".join(sys.argv))
    

    sys.argv is a list that contains all the arguments passed to the script on the command line.

    Basically,

    import sys
    print(sys.argv[1:])
    

提交回复
热议问题