everything I see is about lists but this is about events = queue.queue()
which is a queue with objects that I want to extract, but how would I go about getting the last N elements from that queue?
everything I see is about lists but this is about events = queue.queue()
which is a queue with objects that I want to extract, but how would I go about getting the last N elements from that queue?
By definition, you can't.
What you can do is use a loop or a comprehension to get
the first (you can't get
from the end of a queue
) N elements:
N = 2
first_N_elements = [my_queue.get() for _ in range(N)]