套接字__exit__在python中关闭?

时间:2015-07-24 14:29:27

标签: python sockets python-3.x exit

我想知道是否:

Log.d("newListItems" ,story.toString());

按预期工作。我读到另一个问题,如果套接字的退出函数调用close,它会起作用。据说2.7没有,但我使用3.4而我只是想知道。

1 个答案:

答案 0 :(得分:3)

以下是来自 Python3.4.0 socket.py的代码段:

def __exit__(self, *args):
    if not self._closed:
        self.close()

因此,它会关闭套接字(而不是 Python2.7.10 ,其中__exit__对象没有socket方法。