Can we store socket objects in a Python dictionary. I want to create a socket, store socket object, do some stuff and then read from the socket(search from dictionary to get socketobject).
+7
A:
Yes:
>>> import socket
>>> s = socket.socket()
>>> d = {"key" : s}
>>> d
{'key': <socket._socketobject object at 0x00CEB5A8>}
Vinay Sajip
2009-09-04 09:05:41
Can we compare these socket objects for equality like:if sokObj1 == sokObj2: #Do some operation
Raj
2009-09-15 12:19:09
Which socket objects do you mean, exactly? Obviously if you put `s` into `d` with key "key", then `d["key"]` will return the exact same object `s` which you put in.
Vinay Sajip
2009-09-15 12:33:27