name exit is not defined in python

前端 未结 2 665
太阳男子
太阳男子 2021-01-05 03:39

The following is the code. When I run, I got an error message, saying that \"name exit is not defined\". Could anyone tell me why? Thanks very much for your time and attent

2条回答
  •  孤城傲影
    2021-01-05 04:14

    You need to import sys first, since exit (and argv) is in that module.

    The error I get when I run your code is:

    File "", line 1, in NameError: name 'sys' is not defined

    which is complaining about sys.argv instead of exit. But in either case, the solution -- import sys is the same.

提交回复
热议问题