Python论坛  - 讨论区

标题:[python-chinese] python中对象的构造和析构

2006年06月20日 星期二 15:20

Guorui Ji jiguorui at gmail.com
Tue Jun 20 15:20:28 HKT 2006

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年06月20日 星期二 15:26

Ocean Chen chocean at gmail.com
Tue Jun 20 15:26:17 HKT 2006

__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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年06月20日 星期二 15:32

Guorui Ji jiguorui at gmail.com
Tue Jun 20 15:32:05 HKT 2006

谢谢,惭愧,没仔细阅读文档

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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号