exit() or sys.exit()

B

Brendan

What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.

Aside: Just used a python dictionary in which the keys were compiled
regular expressions. Provided a very elegant solution. Have to love it.
 
T

Tim Chase

Brendan said:
What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.

In Python <=2.4 you had to use sys.exit() because
__builtins__.exit() griped:

tchase@asgix:~$ python2.4
Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more
information. Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: 'str' object is not callable

In 2.5, it's an instance of site.Quitter which is callable,
allowing it to behave like sys.exit() (from my observations,
__builtins__.exit() and sys.exit() behave the same).

I tend to use sys.exit() because I've still got code running on
machines mired at 2.4

-tkc
 
B

Brendan

Brendan said:
What is the difference on exit() and sys.exit() when called in the
main body of a script? From the command line they seem to have the
same effect.

In Python <=2.4 you had to use sys.exit() because
__builtins__.exit() griped:

   tchase@asgix:~$ python2.4
   Python 2.4.4 (#2, Apr 15 2008, 23:43:20)
   [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
   >>> type(exit)
   <type 'str'>
   >>> exit()
   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   TypeError: 'str' object is not callable

In 2.5, it's an instance of site.Quitter which is callable,
allowing it to behave like sys.exit()  (from my observations,
__builtins__.exit() and sys.exit() behave the same).

I tend to use sys.exit() because I've still got code running on
machines mired at 2.4

-tkc

Okay. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top