Exiting from python Command Line





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







113















To exit from Python command line, I have to type exit(). If I type exit, it says



Use exit() or Ctrl-Z plus Return to exit


Usually when you type exit, you would want to exit the program. Why does the interpreter give me the above error when it knows I am trying to exit the command line? Why doesn't it just exit? I know it doesn't matter and its a silly question but I am curious.










share|improve this question























  • It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

    – summea
    Mar 16 '12 at 0:59













  • right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

    – Ank
    Mar 16 '12 at 1:00






  • 1





    exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

    – Paulo Carvalho
    Jan 28 at 13:12


















113















To exit from Python command line, I have to type exit(). If I type exit, it says



Use exit() or Ctrl-Z plus Return to exit


Usually when you type exit, you would want to exit the program. Why does the interpreter give me the above error when it knows I am trying to exit the command line? Why doesn't it just exit? I know it doesn't matter and its a silly question but I am curious.










share|improve this question























  • It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

    – summea
    Mar 16 '12 at 0:59













  • right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

    – Ank
    Mar 16 '12 at 1:00






  • 1





    exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

    – Paulo Carvalho
    Jan 28 at 13:12














113












113








113


11






To exit from Python command line, I have to type exit(). If I type exit, it says



Use exit() or Ctrl-Z plus Return to exit


Usually when you type exit, you would want to exit the program. Why does the interpreter give me the above error when it knows I am trying to exit the command line? Why doesn't it just exit? I know it doesn't matter and its a silly question but I am curious.










share|improve this question














To exit from Python command line, I have to type exit(). If I type exit, it says



Use exit() or Ctrl-Z plus Return to exit


Usually when you type exit, you would want to exit the program. Why does the interpreter give me the above error when it knows I am trying to exit the command line? Why doesn't it just exit? I know it doesn't matter and its a silly question but I am curious.







python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 16 '12 at 0:57









AnkAnk

2,245184586




2,245184586













  • It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

    – summea
    Mar 16 '12 at 0:59













  • right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

    – Ank
    Mar 16 '12 at 1:00






  • 1





    exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

    – Paulo Carvalho
    Jan 28 at 13:12



















  • It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

    – summea
    Mar 16 '12 at 0:59













  • right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

    – Ank
    Mar 16 '12 at 1:00






  • 1





    exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

    – Paulo Carvalho
    Jan 28 at 13:12

















It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

– summea
Mar 16 '12 at 0:59







It might have to do with how functions are often called with () at the end... otherwise, it might (possibly) be a variable... or some sort of object...

– summea
Mar 16 '12 at 0:59















right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

– Ank
Mar 16 '12 at 1:00





right but the interpreter knows that i'm trying to exit and thats why prints that message. otherwise it would have printed an error message. If it knows i'm trying to exit, it can just exit.

– Ank
Mar 16 '12 at 1:00




1




1





exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

– Paulo Carvalho
Jan 28 at 13:12





exit or exit() throws an error for me about 20% of installations I've found in the world... Only CTRL+Z + return consistently works.

– Paulo Carvalho
Jan 28 at 13:12












11 Answers
11






active

oldest

votes


















12














In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)



In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.






share|improve this answer





















  • 1





    That was from Active Python.

    – Ank
    Mar 16 '12 at 1:04








  • 6





    Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

    – Karl Knechtel
    Mar 16 '12 at 1:10











  • @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

    – Dunes
    Mar 16 '12 at 1:15



















43














This works for me, best way to come out of python prompt.




exit()







share|improve this answer































    36














    When you type exit in the command line, it finds the variable with that name and calls __repr__ (or __str__) on it. Usually, you'd get a result like:



    <function exit at 0x00B97FB0>


    But they decided to redefine that function for the exit object to display a helpful message instead. Whether or not that's a stupid behavior or not, is a subjective question, but one possible reason why it doesn't "just exit" is:



    Suppose you're looking at some code in a debugger, for instance, and one of the objects references the exit function. When the debugger tries to call __repr__ on that object to display that function to you, the program suddenly stops! That would be really unexpected, and the measures to counter that might complicate things further (for instance, even if you limit that behavior to the command line, what if you try to print some object that have exit as an attribute?)






    share|improve this answer



















    • 4





      In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

      – Michael Dillon
      Mar 16 '12 at 3:18



















    18














    I recommend you exit the Python interpreter with Ctrl-D. This is the old ASCII code for end-of-file or end-of-transmission.






    share|improve this answer
























    • Only way that worked for me...

      – Mike Wise
      Nov 20 '15 at 13:18











    • Seems like this method doesn't work if the script ran into an error.

      – blaylockbk
      Dec 6 '16 at 20:55



















    17














    This message is the __str__ attribute of exit



    look at these examples :



    1



    >>> print exit
    Use exit() or Ctrl-D (i.e. EOF) to exit


    2



    >>> exit.__str__()
    'Use exit() or Ctrl-D (i.e. EOF) to exit'


    3



    >>> getattr(exit, '__str__')()
    'Use exit() or Ctrl-D (i.e. EOF) to exit'





    share|improve this answer































      7














      Because the interpreter is not a shell where you provide commands, it's - well - an interpreter. The things that you give to it are Python code.



      The syntax of Python is such that exit, by itself, cannot possibly be anything other than a name for an object. Simply referring to an object can't actually do anything (except what the read-eval-print loop normally does; i.e. display a string representation of the object).






      share|improve this answer































        4














        With Anaconda 4.5+ and Python 3.6+ on Windows use



        Ctrl+Z


        or



        exit()


        In some cases, you might have to use



        Ctrl+Break


        If your computer doesn't have Break key then see here.






        share|improve this answer

































          3














          You can fix that.



          Link PYTHONSTARTUP to a python file with the following



          # Make exit work as expected
          type(exit).__repr__ = type(exit).__call__




          How does this work?



          The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result.



          When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system. When you type exit it evaluates to the same callable object, without calling it the object is printed which in turn calls __repr__ on the object.



          We can take advantage of this by linking __repr__ to __call__ and thus get the expected behavior of exiting the sustem even when we type exit without parentheses.






          share|improve this answer





















          • 2





            They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

            – Przemek D
            May 8 '18 at 7:54





















          0














          If you stuck in python command line and none of above solutions worked for you,
          try exit(2)






          share|improve this answer































            0














            To exit from Python terminal, simply just do:



            exit()


            Please pay attention it's a function which called as most user mix it with exit without calling, but new Pyhton terminal show a message...



            or as a shortcut, press:



            Ctrl + D


            on your keyboard...



            ctrl + D






            share|improve this answer





















            • 1





              Everything you said has been covered in the answers above already.

              – Przemek D
              Nov 6 '18 at 12:41



















            -1














            "exit" is a valid variable name that can be used in your Python program. You wouldn't want to exit the interpreter when you're just trying to see the value of that variable.






            share|improve this answer
























            • Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

              – Przemek D
              Nov 6 '18 at 12:38










            protected by Josh Crozier Oct 19 '18 at 18:30



            Thank you for your interest in this question.
            Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



            Would you like to answer one of these unanswered questions instead?














            11 Answers
            11






            active

            oldest

            votes








            11 Answers
            11






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            12














            In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)



            In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.






            share|improve this answer





















            • 1





              That was from Active Python.

              – Ank
              Mar 16 '12 at 1:04








            • 6





              Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

              – Karl Knechtel
              Mar 16 '12 at 1:10











            • @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

              – Dunes
              Mar 16 '12 at 1:15
















            12














            In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)



            In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.






            share|improve this answer





















            • 1





              That was from Active Python.

              – Ank
              Mar 16 '12 at 1:04








            • 6





              Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

              – Karl Knechtel
              Mar 16 '12 at 1:10











            • @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

              – Dunes
              Mar 16 '12 at 1:15














            12












            12








            12







            In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)



            In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.






            share|improve this answer















            In my python interpreter exit is actually a string and not a function -- 'Use Ctrl-D (i.e. EOF) to exit.'. You can check on your interpreter by entering type(exit)



            In active python what is happening is that exit is a function. If you do not call the function it will print out the string representation of the object. This is the default behaviour for any object returned. It's just that the designers thought people might try to type exit to exit the interpreter, so they made the string representation of the exit function a helpful message. You can check this behaviour by typing str(exit) or even print exit.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 16 '12 at 1:16

























            answered Mar 16 '12 at 1:03









            DunesDunes

            24.9k44869




            24.9k44869








            • 1





              That was from Active Python.

              – Ank
              Mar 16 '12 at 1:04








            • 6





              Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

              – Karl Knechtel
              Mar 16 '12 at 1:10











            • @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

              – Dunes
              Mar 16 '12 at 1:15














            • 1





              That was from Active Python.

              – Ank
              Mar 16 '12 at 1:04








            • 6





              Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

              – Karl Knechtel
              Mar 16 '12 at 1:10











            • @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

              – Dunes
              Mar 16 '12 at 1:15








            1




            1





            That was from Active Python.

            – Ank
            Mar 16 '12 at 1:04







            That was from Active Python.

            – Ank
            Mar 16 '12 at 1:04






            6




            6





            Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

            – Karl Knechtel
            Mar 16 '12 at 1:10





            Ctrl-Z is what you do on Windows (well, DOS) where you would do Ctrl-D on Unix-like systems.

            – Karl Knechtel
            Mar 16 '12 at 1:10













            @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

            – Dunes
            Mar 16 '12 at 1:15





            @KarlKnechtel Ah, good to know. I have little experience of programming on windows.

            – Dunes
            Mar 16 '12 at 1:15













            43














            This works for me, best way to come out of python prompt.




            exit()







            share|improve this answer




























              43














              This works for me, best way to come out of python prompt.




              exit()







              share|improve this answer


























                43












                43








                43







                This works for me, best way to come out of python prompt.




                exit()







                share|improve this answer













                This works for me, best way to come out of python prompt.




                exit()








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 29 '16 at 8:58









                Sreedhar GSSreedhar GS

                1,85311622




                1,85311622























                    36














                    When you type exit in the command line, it finds the variable with that name and calls __repr__ (or __str__) on it. Usually, you'd get a result like:



                    <function exit at 0x00B97FB0>


                    But they decided to redefine that function for the exit object to display a helpful message instead. Whether or not that's a stupid behavior or not, is a subjective question, but one possible reason why it doesn't "just exit" is:



                    Suppose you're looking at some code in a debugger, for instance, and one of the objects references the exit function. When the debugger tries to call __repr__ on that object to display that function to you, the program suddenly stops! That would be really unexpected, and the measures to counter that might complicate things further (for instance, even if you limit that behavior to the command line, what if you try to print some object that have exit as an attribute?)






                    share|improve this answer



















                    • 4





                      In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                      – Michael Dillon
                      Mar 16 '12 at 3:18
















                    36














                    When you type exit in the command line, it finds the variable with that name and calls __repr__ (or __str__) on it. Usually, you'd get a result like:



                    <function exit at 0x00B97FB0>


                    But they decided to redefine that function for the exit object to display a helpful message instead. Whether or not that's a stupid behavior or not, is a subjective question, but one possible reason why it doesn't "just exit" is:



                    Suppose you're looking at some code in a debugger, for instance, and one of the objects references the exit function. When the debugger tries to call __repr__ on that object to display that function to you, the program suddenly stops! That would be really unexpected, and the measures to counter that might complicate things further (for instance, even if you limit that behavior to the command line, what if you try to print some object that have exit as an attribute?)






                    share|improve this answer



















                    • 4





                      In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                      – Michael Dillon
                      Mar 16 '12 at 3:18














                    36












                    36








                    36







                    When you type exit in the command line, it finds the variable with that name and calls __repr__ (or __str__) on it. Usually, you'd get a result like:



                    <function exit at 0x00B97FB0>


                    But they decided to redefine that function for the exit object to display a helpful message instead. Whether or not that's a stupid behavior or not, is a subjective question, but one possible reason why it doesn't "just exit" is:



                    Suppose you're looking at some code in a debugger, for instance, and one of the objects references the exit function. When the debugger tries to call __repr__ on that object to display that function to you, the program suddenly stops! That would be really unexpected, and the measures to counter that might complicate things further (for instance, even if you limit that behavior to the command line, what if you try to print some object that have exit as an attribute?)






                    share|improve this answer













                    When you type exit in the command line, it finds the variable with that name and calls __repr__ (or __str__) on it. Usually, you'd get a result like:



                    <function exit at 0x00B97FB0>


                    But they decided to redefine that function for the exit object to display a helpful message instead. Whether or not that's a stupid behavior or not, is a subjective question, but one possible reason why it doesn't "just exit" is:



                    Suppose you're looking at some code in a debugger, for instance, and one of the objects references the exit function. When the debugger tries to call __repr__ on that object to display that function to you, the program suddenly stops! That would be really unexpected, and the measures to counter that might complicate things further (for instance, even if you limit that behavior to the command line, what if you try to print some object that have exit as an attribute?)







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 16 '12 at 1:10









                    mgibsonbrmgibsonbr

                    18.9k75288




                    18.9k75288








                    • 4





                      In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                      – Michael Dillon
                      Mar 16 '12 at 3:18














                    • 4





                      In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                      – Michael Dillon
                      Mar 16 '12 at 3:18








                    4




                    4





                    In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                    – Michael Dillon
                    Mar 16 '12 at 3:18





                    In this case, the real exit function is not even in scope unless you import sys, after which you would call sys.exit() to exit the interpreter.

                    – Michael Dillon
                    Mar 16 '12 at 3:18











                    18














                    I recommend you exit the Python interpreter with Ctrl-D. This is the old ASCII code for end-of-file or end-of-transmission.






                    share|improve this answer
























                    • Only way that worked for me...

                      – Mike Wise
                      Nov 20 '15 at 13:18











                    • Seems like this method doesn't work if the script ran into an error.

                      – blaylockbk
                      Dec 6 '16 at 20:55
















                    18














                    I recommend you exit the Python interpreter with Ctrl-D. This is the old ASCII code for end-of-file or end-of-transmission.






                    share|improve this answer
























                    • Only way that worked for me...

                      – Mike Wise
                      Nov 20 '15 at 13:18











                    • Seems like this method doesn't work if the script ran into an error.

                      – blaylockbk
                      Dec 6 '16 at 20:55














                    18












                    18








                    18







                    I recommend you exit the Python interpreter with Ctrl-D. This is the old ASCII code for end-of-file or end-of-transmission.






                    share|improve this answer













                    I recommend you exit the Python interpreter with Ctrl-D. This is the old ASCII code for end-of-file or end-of-transmission.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 16 '12 at 1:00









                    Jay SlupeskyJay Slupesky

                    1,7791114




                    1,7791114













                    • Only way that worked for me...

                      – Mike Wise
                      Nov 20 '15 at 13:18











                    • Seems like this method doesn't work if the script ran into an error.

                      – blaylockbk
                      Dec 6 '16 at 20:55



















                    • Only way that worked for me...

                      – Mike Wise
                      Nov 20 '15 at 13:18











                    • Seems like this method doesn't work if the script ran into an error.

                      – blaylockbk
                      Dec 6 '16 at 20:55

















                    Only way that worked for me...

                    – Mike Wise
                    Nov 20 '15 at 13:18





                    Only way that worked for me...

                    – Mike Wise
                    Nov 20 '15 at 13:18













                    Seems like this method doesn't work if the script ran into an error.

                    – blaylockbk
                    Dec 6 '16 at 20:55





                    Seems like this method doesn't work if the script ran into an error.

                    – blaylockbk
                    Dec 6 '16 at 20:55











                    17














                    This message is the __str__ attribute of exit



                    look at these examples :



                    1



                    >>> print exit
                    Use exit() or Ctrl-D (i.e. EOF) to exit


                    2



                    >>> exit.__str__()
                    'Use exit() or Ctrl-D (i.e. EOF) to exit'


                    3



                    >>> getattr(exit, '__str__')()
                    'Use exit() or Ctrl-D (i.e. EOF) to exit'





                    share|improve this answer




























                      17














                      This message is the __str__ attribute of exit



                      look at these examples :



                      1



                      >>> print exit
                      Use exit() or Ctrl-D (i.e. EOF) to exit


                      2



                      >>> exit.__str__()
                      'Use exit() or Ctrl-D (i.e. EOF) to exit'


                      3



                      >>> getattr(exit, '__str__')()
                      'Use exit() or Ctrl-D (i.e. EOF) to exit'





                      share|improve this answer


























                        17












                        17








                        17







                        This message is the __str__ attribute of exit



                        look at these examples :



                        1



                        >>> print exit
                        Use exit() or Ctrl-D (i.e. EOF) to exit


                        2



                        >>> exit.__str__()
                        'Use exit() or Ctrl-D (i.e. EOF) to exit'


                        3



                        >>> getattr(exit, '__str__')()
                        'Use exit() or Ctrl-D (i.e. EOF) to exit'





                        share|improve this answer













                        This message is the __str__ attribute of exit



                        look at these examples :



                        1



                        >>> print exit
                        Use exit() or Ctrl-D (i.e. EOF) to exit


                        2



                        >>> exit.__str__()
                        'Use exit() or Ctrl-D (i.e. EOF) to exit'


                        3



                        >>> getattr(exit, '__str__')()
                        'Use exit() or Ctrl-D (i.e. EOF) to exit'






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 16 '12 at 1:05









                        moulmoul

                        468210




                        468210























                            7














                            Because the interpreter is not a shell where you provide commands, it's - well - an interpreter. The things that you give to it are Python code.



                            The syntax of Python is such that exit, by itself, cannot possibly be anything other than a name for an object. Simply referring to an object can't actually do anything (except what the read-eval-print loop normally does; i.e. display a string representation of the object).






                            share|improve this answer




























                              7














                              Because the interpreter is not a shell where you provide commands, it's - well - an interpreter. The things that you give to it are Python code.



                              The syntax of Python is such that exit, by itself, cannot possibly be anything other than a name for an object. Simply referring to an object can't actually do anything (except what the read-eval-print loop normally does; i.e. display a string representation of the object).






                              share|improve this answer


























                                7












                                7








                                7







                                Because the interpreter is not a shell where you provide commands, it's - well - an interpreter. The things that you give to it are Python code.



                                The syntax of Python is such that exit, by itself, cannot possibly be anything other than a name for an object. Simply referring to an object can't actually do anything (except what the read-eval-print loop normally does; i.e. display a string representation of the object).






                                share|improve this answer













                                Because the interpreter is not a shell where you provide commands, it's - well - an interpreter. The things that you give to it are Python code.



                                The syntax of Python is such that exit, by itself, cannot possibly be anything other than a name for an object. Simply referring to an object can't actually do anything (except what the read-eval-print loop normally does; i.e. display a string representation of the object).







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 16 '12 at 1:13









                                Karl KnechtelKarl Knechtel

                                37.7k56294




                                37.7k56294























                                    4














                                    With Anaconda 4.5+ and Python 3.6+ on Windows use



                                    Ctrl+Z


                                    or



                                    exit()


                                    In some cases, you might have to use



                                    Ctrl+Break


                                    If your computer doesn't have Break key then see here.






                                    share|improve this answer






























                                      4














                                      With Anaconda 4.5+ and Python 3.6+ on Windows use



                                      Ctrl+Z


                                      or



                                      exit()


                                      In some cases, you might have to use



                                      Ctrl+Break


                                      If your computer doesn't have Break key then see here.






                                      share|improve this answer




























                                        4












                                        4








                                        4







                                        With Anaconda 4.5+ and Python 3.6+ on Windows use



                                        Ctrl+Z


                                        or



                                        exit()


                                        In some cases, you might have to use



                                        Ctrl+Break


                                        If your computer doesn't have Break key then see here.






                                        share|improve this answer















                                        With Anaconda 4.5+ and Python 3.6+ on Windows use



                                        Ctrl+Z


                                        or



                                        exit()


                                        In some cases, you might have to use



                                        Ctrl+Break


                                        If your computer doesn't have Break key then see here.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 16 '18 at 11:41

























                                        answered Oct 13 '18 at 1:44









                                        Shital ShahShital Shah

                                        26k511098




                                        26k511098























                                            3














                                            You can fix that.



                                            Link PYTHONSTARTUP to a python file with the following



                                            # Make exit work as expected
                                            type(exit).__repr__ = type(exit).__call__




                                            How does this work?



                                            The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result.



                                            When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system. When you type exit it evaluates to the same callable object, without calling it the object is printed which in turn calls __repr__ on the object.



                                            We can take advantage of this by linking __repr__ to __call__ and thus get the expected behavior of exiting the sustem even when we type exit without parentheses.






                                            share|improve this answer





















                                            • 2





                                              They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                              – Przemek D
                                              May 8 '18 at 7:54


















                                            3














                                            You can fix that.



                                            Link PYTHONSTARTUP to a python file with the following



                                            # Make exit work as expected
                                            type(exit).__repr__ = type(exit).__call__




                                            How does this work?



                                            The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result.



                                            When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system. When you type exit it evaluates to the same callable object, without calling it the object is printed which in turn calls __repr__ on the object.



                                            We can take advantage of this by linking __repr__ to __call__ and thus get the expected behavior of exiting the sustem even when we type exit without parentheses.






                                            share|improve this answer





















                                            • 2





                                              They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                              – Przemek D
                                              May 8 '18 at 7:54
















                                            3












                                            3








                                            3







                                            You can fix that.



                                            Link PYTHONSTARTUP to a python file with the following



                                            # Make exit work as expected
                                            type(exit).__repr__ = type(exit).__call__




                                            How does this work?



                                            The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result.



                                            When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system. When you type exit it evaluates to the same callable object, without calling it the object is printed which in turn calls __repr__ on the object.



                                            We can take advantage of this by linking __repr__ to __call__ and thus get the expected behavior of exiting the sustem even when we type exit without parentheses.






                                            share|improve this answer















                                            You can fix that.



                                            Link PYTHONSTARTUP to a python file with the following



                                            # Make exit work as expected
                                            type(exit).__repr__ = type(exit).__call__




                                            How does this work?



                                            The python command line is a read-evaluate-print-loop, that is when you type text it will read that text, evaluate it, and eventually print the result.



                                            When you type exit() it evaluates to a callable object of type site.Quitter and calls its __call__ function which exits the system. When you type exit it evaluates to the same callable object, without calling it the object is printed which in turn calls __repr__ on the object.



                                            We can take advantage of this by linking __repr__ to __call__ and thus get the expected behavior of exiting the sustem even when we type exit without parentheses.







                                            share|improve this answer














                                            share|improve this answer



                                            share|improve this answer








                                            edited May 11 '18 at 8:48

























                                            answered Mar 20 '18 at 9:17









                                            akuhnakuhn

                                            23.2k25777




                                            23.2k25777








                                            • 2





                                              They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                              – Przemek D
                                              May 8 '18 at 7:54
















                                            • 2





                                              They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                              – Przemek D
                                              May 8 '18 at 7:54










                                            2




                                            2





                                            They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                            – Przemek D
                                            May 8 '18 at 7:54







                                            They took the effort to make exit print the "helpful" string, but they couldn't just bind it to do the natural thing and exit the interpreter. Being forced to type the parentheses every time is frustrating. This answer is perfect and should be the accepted one instead.

                                            – Przemek D
                                            May 8 '18 at 7:54













                                            0














                                            If you stuck in python command line and none of above solutions worked for you,
                                            try exit(2)






                                            share|improve this answer




























                                              0














                                              If you stuck in python command line and none of above solutions worked for you,
                                              try exit(2)






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                If you stuck in python command line and none of above solutions worked for you,
                                                try exit(2)






                                                share|improve this answer













                                                If you stuck in python command line and none of above solutions worked for you,
                                                try exit(2)







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Aug 15 '18 at 19:35









                                                Mahdi BaghbaniMahdi Baghbani

                                                185




                                                185























                                                    0














                                                    To exit from Python terminal, simply just do:



                                                    exit()


                                                    Please pay attention it's a function which called as most user mix it with exit without calling, but new Pyhton terminal show a message...



                                                    or as a shortcut, press:



                                                    Ctrl + D


                                                    on your keyboard...



                                                    ctrl + D






                                                    share|improve this answer





















                                                    • 1





                                                      Everything you said has been covered in the answers above already.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:41
















                                                    0














                                                    To exit from Python terminal, simply just do:



                                                    exit()


                                                    Please pay attention it's a function which called as most user mix it with exit without calling, but new Pyhton terminal show a message...



                                                    or as a shortcut, press:



                                                    Ctrl + D


                                                    on your keyboard...



                                                    ctrl + D






                                                    share|improve this answer





















                                                    • 1





                                                      Everything you said has been covered in the answers above already.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:41














                                                    0












                                                    0








                                                    0







                                                    To exit from Python terminal, simply just do:



                                                    exit()


                                                    Please pay attention it's a function which called as most user mix it with exit without calling, but new Pyhton terminal show a message...



                                                    or as a shortcut, press:



                                                    Ctrl + D


                                                    on your keyboard...



                                                    ctrl + D






                                                    share|improve this answer















                                                    To exit from Python terminal, simply just do:



                                                    exit()


                                                    Please pay attention it's a function which called as most user mix it with exit without calling, but new Pyhton terminal show a message...



                                                    or as a shortcut, press:



                                                    Ctrl + D


                                                    on your keyboard...



                                                    ctrl + D







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited Nov 6 '18 at 12:54

























                                                    answered Aug 18 '18 at 1:44









                                                    AlirezaAlireza

                                                    52.4k14178124




                                                    52.4k14178124








                                                    • 1





                                                      Everything you said has been covered in the answers above already.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:41














                                                    • 1





                                                      Everything you said has been covered in the answers above already.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:41








                                                    1




                                                    1





                                                    Everything you said has been covered in the answers above already.

                                                    – Przemek D
                                                    Nov 6 '18 at 12:41





                                                    Everything you said has been covered in the answers above already.

                                                    – Przemek D
                                                    Nov 6 '18 at 12:41











                                                    -1














                                                    "exit" is a valid variable name that can be used in your Python program. You wouldn't want to exit the interpreter when you're just trying to see the value of that variable.






                                                    share|improve this answer
























                                                    • Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:38
















                                                    -1














                                                    "exit" is a valid variable name that can be used in your Python program. You wouldn't want to exit the interpreter when you're just trying to see the value of that variable.






                                                    share|improve this answer
























                                                    • Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:38














                                                    -1












                                                    -1








                                                    -1







                                                    "exit" is a valid variable name that can be used in your Python program. You wouldn't want to exit the interpreter when you're just trying to see the value of that variable.






                                                    share|improve this answer













                                                    "exit" is a valid variable name that can be used in your Python program. You wouldn't want to exit the interpreter when you're just trying to see the value of that variable.







                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Aug 15 '18 at 20:07









                                                    Chad KennedyChad Kennedy

                                                    1,202614




                                                    1,202614













                                                    • Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:38



















                                                    • Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                      – Przemek D
                                                      Nov 6 '18 at 12:38

















                                                    Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                    – Przemek D
                                                    Nov 6 '18 at 12:38





                                                    Except if you assign to exit, you override this symbol, and exit() will no longer work. Although this symbol is a valid variable name, using it in such a way doesn't seem to be a very good practice.

                                                    – Przemek D
                                                    Nov 6 '18 at 12:38





                                                    protected by Josh Crozier Oct 19 '18 at 18:30



                                                    Thank you for your interest in this question.
                                                    Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).



                                                    Would you like to answer one of these unanswered questions instead?



                                                    Popular posts from this blog

                                                    Florida Star v. B. J. F.

                                                    Danny Elfman

                                                    Lugert, Oklahoma