Alex Rivera | Logout

Exiting from python Command Line

Asked 2012-03-16T00:57:56.610
197

Typing exit() exits from Python command line. Typing exit says:

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

When you type exit, you want to exit. Why does the interpreter give me the above error when it knows I am trying to exit? Why doesn't it just exit?

Edit
Report

1 Answer

22

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'
answered 2012-03-16T01:05:31.463

Your Answer