IronReign IronReign - 8 months ago 31
Python Question

Send a message multiple times all at once in Python

In python 3.5 is it possible to send multiple messages with

sock.send(msg) * 10
. In this case will it send 10 times or just one time and have some sort of error in the background?


if list-creation side-effect is not a problem, then you can do it as a list comprehension as well:

[sock.send(msg) for _ in range(10)] 

_ is a sort of "throwaway" variable, you can use any other identifier name there.