如果我想创建一个有边界的队列,但我想在函数内部为队列创建边界,而不是使用 Class BoundedQueue.Queue(maxsize = 4),该怎么办?(有关最大绑定队列的信息:http: //docs.python.org/2/library/queue.html)
有什么建议么?
这是我的代码;capacity
是最大界限。
class BoundedQueue:
# Constructor, which creates a new empty queue, with user-specified capacity:
def __init__(self, capacity):
self.items = []
assert(capacity >= 0), "not positive"
try:
capacity = int(capacity)
except TypeError as inst:
print("Error", inst.args)
except:
print("error")
else:
itemmax = capacity