IronReign IronReign - 1 year ago 67
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download