Run python script with some of the argument that are optional

后端 未结 4 835
慢半拍i
慢半拍i 2021-02-06 04:53

I have gone through the sys documentation, however there is something that is still unclear to me. I have looked for some similar question on stackoverflow, but I h

4条回答
  •  后悔当初
    2021-02-06 05:04

    Other than using argparse (which I do recommend), this can be solved by slicing and expanding:

        sys.exit(example(*sys.argv[1:7]))
    

    The slice will only contain elements that actually exist, even if there aren't enough to fulfill the size of slice requested.

提交回复
热议问题