Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我一直在用 python 编写一个套接字服务器。我想向某些用户发送数据(对所有人都没有),但我不知道该怎么做。我可以用 for 循环发送它吗?
例如:
some_clients = [client1, client2, client5, client9] for client in some_clients: client.send("data")
这很好?
如果这行得通,那就完全没问题了。
如果你想要更具可读性的东西,你可以这样做:
for client in filter(shouldrecieve, all_clients): client.send(data)
或类似的东西:
for client in (client for client in all_clients if client.attrspam == barfoo): client.send(data)