I build an app compatible between Python 2 and 3. In order to provide compatibility between those two Python versions, I use six library.
My code uses sockets. Under Python 3 it is possible to create them using with statement, but under Python 2 it claims on missing __exit__ attribute.
Is there any function of six providing disposable socket? If not, what solution would you consider as the most clear in this case?
AFAIK (by scanning through its docs)
sixdoesn't do much in this case. In Python 2, you could wrapsocketup in a context manager with thecontextmanagerdecorator and supply that:In both cases you use the
withstatement accordingly: