@@ -39,7 +39,7 @@ internal error is detected, or when :func:`os._exit` is called.
39
39
40
40
If an exception is raised during execution of the exit handlers, a traceback is
41
41
printed (unless :exc: `SystemExit ` is raised) and the exception information is
42
- saved. After all exit handlers have had a chance to run the last exception to
42
+ saved. After all exit handlers have had a chance to run, the last exception to
43
43
be raised is re-raised.
44
44
45
45
This function returns *func *, which makes it possible to use it as a
@@ -73,7 +73,7 @@ automatically when the program terminates without relying on the application
73
73
making an explicit call into this module at termination. ::
74
74
75
75
try:
76
- with open(" counterfile" ) as infile:
76
+ with open(' counterfile' ) as infile:
77
77
_count = int(infile.read())
78
78
except FileNotFoundError:
79
79
_count = 0
@@ -83,21 +83,22 @@ making an explicit call into this module at termination. ::
83
83
_count = _count + n
84
84
85
85
def savecounter():
86
- with open(" counterfile", "w" ) as outfile:
87
- outfile.write("%d" % _count)
86
+ with open(' counterfile', 'w' ) as outfile:
87
+ outfile.write('%d' % _count)
88
88
89
89
import atexit
90
+
90
91
atexit.register(savecounter)
91
92
92
93
Positional and keyword arguments may also be passed to :func: `register ` to be
93
94
passed along to the registered function when it is called::
94
95
95
96
def goodbye(name, adjective):
96
- print('Goodbye, %s, it was %s to meet you.' % (name, adjective))
97
+ print('Goodbye %s, it was %s to meet you.' % (name, adjective))
97
98
98
99
import atexit
99
- atexit.register(goodbye, 'Donny', 'nice')
100
100
101
+ atexit.register(goodbye, 'Donny', 'nice')
101
102
# or:
102
103
atexit.register(goodbye, adjective='nice', name='Donny')
103
104
@@ -107,6 +108,6 @@ Usage as a :term:`decorator`::
107
108
108
109
@atexit.register
109
110
def goodbye():
110
- print(" You are now leaving the Python sector." )
111
+ print(' You are now leaving the Python sector.' )
111
112
112
113
This only works with functions that can be called without arguments.
0 commit comments