[Tutor] there is no exitfunc in sys module

Alan Gauld alan.gauld at blueyonder.co.uk
Sat Jan 24 12:56:10 EST 2004


>  i was reading the manual for sys module. i found a
> description for a function known as exitfunc....
> interpreter exits. but when i try to call this
> function on Python interactive prompt it says there is
> no attribute named exitfunc in sys module.

Doing help(sys) yields this:

exitfunc -- if sys.exitfunc exists, this routine is called when Python
exits
      Assigning to sys.exitfunc is deprecated; use the atexit module
instead.

So the note tells us that exitfunc does not exist by default
you have to create it. However it also tells us that this is
deprecated - ie old fashioned and becoming obsolete - you should
use atexit instead

However just to illustrate how exitfun can be used:

>>> import sys
>>> def f(): print "GOOOODBYEEEE!"
...
>>> sys.exitfunc = f
>>> sys.exit()
GOOOODBYEEEE!

So you assign a function to sys.exitfunc and when you call
sys.exit() to exit it in turn calls your exit function.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list