<p>{1}写在API上。我使用<a href="http://eli.thegreenplace.net/2009/06/12/safely-using-destructors-in-python" rel="nofollow noreferrer">this</a>文章作为<code>python</code>析构函数的帮助。在</p>
<pre><code># api.py
class ApiCfg(object):
def __init__(self, ...):
# open a connection to a device
some_device_open()
def __del__(self):
print 'Close a connection to some_device'
# close a connection to a device
some_device_close()
# Some code
...
api_cfg = ApiCfg()
# myfile.py
from api import *
# Do some stuff
api.run()
</code></pre>
<p>我希望在我的屏幕上看到的是这样一个语句:<code>Close connection to some device</code>。但是由于某些原因我不知道。有人能解释一下为什么会这样吗?在</p>