2006年06月20日 星期二 15:20
class A: __init__(self, filename): self.file = file(filename) …… __init__相当于class A 的构造函数(没错吧?),在init里我file打开了一个文件 那么,我希望在析构函数里执行self.file.close() 可是,python里似乎没有系构函数???是这样的吗? 有没有合理的替代方案? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060620/654b77fa/attachment.html
2006年06月20日 星期二 15:26
__del__() 在06-6-20,Guorui Ji <jiguorui at gmail.com> 写道: > > class A: > __init__(self, filename): > > self.file = file(filename) > …… > __init__相当于class A 的构造函数(没错吧?),在init里我file打开了一个文件 > 那么,我希望在析构函数里执行self.file.close() > > 可是,python里似乎没有系构函数???是这样的吗? > 有没有合理的替代方案? > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -- Ocean mail: chocean at gmail.com homepage: www.oceanisland.com.cn -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060620/52a267fa/attachment.htm
2006年06月20日 星期二 15:32
谢谢,惭愧,没仔细阅读文档 On 6/20/06, Ocean Chen <chocean at gmail.com> wrote: > > __del__() > > 在06-6-20,Guorui Ji <jiguorui at gmail.com> 写道: > > > > class A: > __init__(self, filename): > > self.file = file(filename) > …… > __init__相当于class A 的构造函数(没错吧?),在init里我file打开了一个文件 > 那么,我希望在析构函数里执行self.file.close() > > 可是,python里似乎没有系构函数???是这样的吗? > 有没有合理的替代方案? > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > -- > Ocean > mail: chocean at gmail.com > homepage: www.oceanisland.com.cn > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060620/d43210fa/attachment.htm
Zeuux © 2025
京ICP备05028076号