What does [sock] = func () mean?

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 have never seen this from Tornado.

+6
source share
2 answers

The function returns an element inside the container, and the author wants sock attached to the element, not the container.

Here is a simpler example of this syntax:

 >>> def foo(): ... return ['potato'] ... >>> [p] = foo() >>> p 'potato' 
+6
source

Here it is:

 sock, = netutil.bind_sockets(None, 'localhost', family=socket.AF_INET) 

the right side contains only one element.

+2
source

All Articles