class Buffer(object): """ """ def __init__(self, name, size_total, size_in_cache): self.name = name self.size_total = size_total class Storage(object): """ """ def __init__(self, capacity): self.CAPACITY = capacity self.contents = collections.deque() self.capacity_used = 0 def push_to_contents(self, buffer_name, buffer_size): buf = Buffer(buffer_name, buffer_size) self.contents.appendleft(buf) def delete_from_contents(self, buffer_name) """ HOW?? How can I use self.contents.remove() here> """
collections.deque.removeoperates is by comparing the argument to each item in the deque. If it finds something which is equal to the argument, it removes it. Otherwise, it raises a
Bufferobject, as you've implemented it, doesn't know how to compare itself with other objects, Python defaults (using the
objectparent class) to comparing the
However, if you were to implement the
__eq__method for your class, you could accomplish what you're looking for.
This is all fine and good if you're using Python 3. In Python 2, you have to implement
__ne__("not equal") as well. It can be as simple as