[Python-bugs-list] [ python-Bugs-810214 ] exit() raises exception

SourceForge.net noreply at sourceforge.net
Sun Sep 28 11:27:25 EDT 2003


Bugs item #810214, was opened at 2003-09-21 20:36
Message generated for change (Comment added) made by jojoworks
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=810214&group_id=5470

Category: None
Group: None
>Status: Closed
Resolution: None
Priority: 5
Submitted By: Jozef Behran (jojoworks)
Assigned to: Nobody/Anonymous (nobody)
Summary: exit() raises exception

Initial Comment:
--- BEGIN OF SESSION TRANSCRIPT ---

$ python

Python version: 2.2.2 (#2, Feb 5 2003, 10:40:08)

[GCC 3.2.1 (Mandrake Linux 9.1 3.2.1-5mdk)] on linux-i386

Type "help", "copyright", "credits" or "license" for

more information.

>>> <CTRL-D>

$ cat exit.py

exit(1)

$ python exit.py

Traceback (most recent call last):

  File "exit.py", line 1, in ?

    exit(1);

TypeError: 'str' object is not callable

$ cat exitstr.py

exit("Fatal error")

$ python exitstr.py

Traceback (most recent call last):

  File "exitstr.py", line 1, in ?

    exit("Fatal error");

TypeError: 'str' object is not callable

--- END OF SESSION TRANSCRIPT ---



The first "python ..." command shall output nothing and

return 1 as the result. The second "python ..." command

shall output "Fatal error" to stderr and return 1 as

the result. No exception shall be raised there.



----------------------------------------------------------------------

>Comment By: Jozef Behran (jojoworks)
Date: 2003-09-28 17:27

Message:
Logged In: YES 
user_id=688090

Thanks. Now I looked at the example I was looking in my book

before and I did realized that they used unobtrusive "from

sys import exit" line at the *bottom* of the example script.

When you are working with compiled languages such as C for

so long time, the way you reads programs will be affected so

that you will get *really* confused if you see such a piece

of example code. So when I looked at the code and saw

"exit()" call, I thought that the exit() is a builtin

function (it was very long example and the exit() call was

on different page as the "from sys import exit" line, so I

didn't notice the import at first look) and when I got that

exception, I began to think about a bug being in Python

(after I really carefully compared to the example I was

looking on ;) ).



P.S. I'm closing this "bug" when I realized that there is no

such a bug in Python.



P.SS. I suggest you to not define the builtin "exit" when

you are not in the interactive mode (i.e. running a script)

to avoid further such confusions.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-09-21 22:51

Message:
Logged In: YES 
user_id=31435

Oops!  Everywhere I wrote "os" read "sys" instead.  The 

sys.exit() function does what you want here.  There is no exit 

function in the os module (although there is a lower-level 

os._exit() function).

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2003-09-21 22:42

Message:
Logged In: YES 
user_id=31435

It appears that you want to use the os.exit() function.  If so, 

you must import it from os.  The builtin exit (which you're 

using) is indeed just a string, which displays a message to 

interactive users telling them the correct way to end an 

interpreter session.  This varies across platforms.  For 

example, here under Cygwin:



$ python

Python 2.2.2 (#1, Dec 31 2002, 12:24:34)

[GCC 3.2 20020927 (prerelease)] on cygwin

Type "help", "copyright", "credits" or "license" for more 

information.

>>> exit

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

>>>



"'str' object is not callable" is a perfectly appropriate 

exception if you try to (as you are trying to do) *call* a 

string with an argument.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=810214&group_id=5470



More information about the Python-bugs-list mailing list