2 years ago
#34332
Shastaz
Why not assign a variable instead of using `with .. as`?
I'm learning socket programming in Python, and saw that a person used this piece of code:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
Why would you use with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s
instead of s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
? Is there any difference between these which makes one better to use in this case?
python
sockets
python-sockets
0 Answers
Your Answer