What does this line of code mean, from tornado
?
[sock] = netutil.bind_sockets(None, 'localhost', family=socket.AF_INET)
I understand these assignments: list[index] = val
, list[index1:index2] = list2
, but I've never seen that from Tornado.
The function returns an element inside a container, and the author wants sock
bound to the element, not to the container.
Here is a more simple example of that syntax:
>>> def foo():
... return ['potato']
...
>>> [p] = foo()
>>> p
'potato'
Here, it equals to:
sock, = netutil.bind_sockets(None, 'localhost', family=socket.AF_INET)
right hand side only contains one element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With