python模块

2017-09-19  本文已影响0人  老夫刘某

该模块定义了一个注册清除功能的功能,如此注册的功能在正常的解释器终止时自动执行.

[root@centos3 liujiangbu]# vim 2.py

file = open('test.txt','a')
def goodbye(name, adjective):
print('Goodbye, %s, it was %s to meet you.' % (name, adjective))

import atexit
t = input("qingshurunidemingzi:")
q = input("qingshushurnfsdff:")

file.write(q)
file.close()

atexit.register(goodbye, adjective='nice', name='Donny')
print(file)

def test(q):
print(q)

test(q)
print(6666)

执行结果:
[root@centos3 liujiangbu]# python3 2.py
qingshurunidemingzi:ddd
qingshushurnfsdff:ddd
<_io.TextIOWrapper name='test.txt' mode='a' encoding='UTF-8'>
ddd
6666
Goodbye, Donny, it was nice to meet you.

可以看到atexit.register(goodbye, adjective='nice', name='Donny')调用的函数最后被执行

上一篇 下一篇

猜你喜欢

热点阅读