Python dictionary for storing socket objects

Can we store socket objects in a Python dictionary. I want to create a socket, save the socket object, do some things, and then read from the socket (search from a dictionary to get socketobject).

+3
source share
1 answer

Yes:

>>> import socket
>>> s = socket.socket()
>>> d = {"key" : s}
>>> d
{'key': <socket._socketobject object at 0x00CEB5A8>}
+10
source

Source: https://habr.com/ru/post/1716884/


All Articles