[Tutor] there is no exitfunc in sys module
alan.gauld at blueyonder.co.uk
Sat Jan 24 18:56:10 CET 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
Assigning to sys.exitfunc is deprecated; use the atexit module
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
So you assign a function to sys.exitfunc and when you call
sys.exit() to exit it in turn calls your exit function.
Author of the Learn to Program web tutor
More information about the Python-list