ankur katiyar
ankur katiyar

Reputation: 101

What is the pythonic way to simply use one value or a few values when a function returns multiple values?

I am using a python socket and one of the API of the socket is

 (clientsocket, address) = serversocket.accept()

My magic number way is

 connected_sock = serversocket.accept()[0]

However, I am interested only in client socket and not address. I can do so that there is just the client socket value and not address. What is the appropriate way in Python to do so that I can avoid magic numbers in my code?

Upvotes: 2

Views: 41

Answers (1)

enzo
enzo

Reputation: 11506

You can use _ as a throwaway variable:

clientsocket, _ = serversocket.accept()

Upvotes: 3

Related Questions