美文网首页
python模块

python模块

作者: 老夫刘某 | 来源:发表于2017-09-19 17:35 被阅读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')调用的函数最后被执行

相关文章

网友评论

      本文标题:python模块

      本文链接:https://www.haomeiwen.com/subject/enhgsxtx.html