How to read/process command line arguments?

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

    If you need something fast and not very flexible

    main.py:

    import sys
    
    first_name = sys.argv[1]
    last_name = sys.argv[2]
    print("Hello " + first_name + " " + last_name)
    

    Then run python main.py James Smith

    to produce the following output:

    Hello James Smith

提交回复
热议问题