Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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've never seen that from Tornado.

like image 989
adamsmith Avatar asked Dec 23 '13 13:12

adamsmith


2 Answers

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'
like image 93
wim Avatar answered Oct 10 '22 15:10

wim


Here, it equals to:

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

right hand side only contains one element.

like image 39
iMom0 Avatar answered Oct 10 '22 14:10

iMom0