Checking the number of command line arguments in python

前端 未结 2 2313
忘掉有多难
忘掉有多难 2021-02-20 10:24

I\'m new to python. Still getting my feet wet. I\'m trying to do something like this:

import sys

if ((len(sys.argv) < 3 or < len(sys.argv > 3)):
             


        
2条回答
  •  北海茫月
    2021-02-20 11:14

    sys has a function called exit:

    sys.exit(1)
    

    is probably what you want. Using 1 tells the program calling your program that there was an error. You should probably consider writing to sys.stderr the reason for the error.

提交回复
热议问题