现在我学习了python的simpy
库。
你能解释一下为什么在这个example中使用bitwise-or
吗? 。为什么我们不能使用简单的 or
语句。
results = yield req | env.timeout(patience)
最佳答案
来自 SimPy 的文档 Core Event Types
This class also implements and() (&) and or() (|). If you concatenate two events using one of these operators, a Condition event is generated that lets you wait for both or one of them.
这意味着 req
和 env.timeout(patience)
都是事件,我们将生成第一个发生的事件。即
results = yield (req | env.timeout(patience))
要回答您最初的问题,您似乎可以使用 or
来代替,但这可能不会使实际情况变得更清晰,并且如果人们认为它是常规的旧 or ,则可能会导致编辑错误
.
关于Python-简单的按位或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36066542/