目录

* 一、__del__ <https://www.cnblogs.com/nickchen121/p/10991095.html#一__del__>
一、__del__

*
__del__也称之为析构方法

*
__del__会在对象被删除之前自动触发


class People: def __init__(self, name, age): self.name = name self.age = age
self.f = open('test.txt', 'w', encoding='utf-8') def __del__(self):
print('run======>') # 做回收系统资源相关的事情 self.f.close() obj = People('egon', 18) del
obj # del obj会间接删除f的内存占用,但是还需要自定制__del__删除文件的系统占用 print('主') run=-====> 主

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信