close

[Solved] NameError: name ‘exit’ is not defined

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error NameError: name ‘exit’ is not defined in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How NameError: name ‘exit’ is not defined Error Occurs?

Today I get the following error NameError: name ‘exit’ is not defined in python.

How To Solve NameError: name ‘exit’ is not defined Error ?

  1. How To Solve NameError: name 'exit' is not defined Error ?

    To Solve NameError: name 'exit' is not defined Error Importing sys will not be enough to make exit live in the global scope.

  2. NameError: name 'exit' is not defined

    To Solve NameError: name 'exit' is not defined Error Importing sys will not be enough to make exit live in the global scope.

Solution 1

Importing sys will not be enough to make exit live in the global scope.

You either need to do

from sys import exit
exit()

or

import sys
sys.exit()

Note that, as you are also using argv, in the first case you should do from sys import argv,exit

Solution 2

You have to apply the function to sys:

from sys import exit
exit()

because exit is the function itself, you need to call it with ()

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read