Check maxlen of deque in python 2.6
deque, python, python-2.6
Solution
I would create my own `deque` by inheriting from `collections.deque`. It is not difficult. Namely, here it is:
import collections
class deque(collections.deque):
def __init__(self, iterable=(), maxlen=None):
super(deque, self).__init__(iterable, maxlen)
self._maxlen = maxlen
@property
def maxlen(self):
return self._maxlen
and this is the new deque at work:
>>> d = deque()
>>> print d
deque([])
>>> print d.maxlen
None
>>> d = deque(maxlen=3)
>>> print d
deque([], maxlen=3)
>>> print d.maxlen
3
>>> d = deque(range(5))
>>> print d
deque([0, 1, 2, 3, 4])
>>> print d.maxlen
None
>>> d = deque(range(5), maxlen=3)
>>> print d
deque([2, 3, 4], maxlen=3)
>>> print d.maxlen
3
Problem
I have had to change from python 2.7 to 2.6. I've been using a deque with the maxlen property and have been checking what the maxlen is. Apparently you can use maxlen in python 2.6, but in 2.6 deques do not have a maxlen attribute. What is the cleanest way to check what the maxlen of a deque is in python 2.6? In 2.7: ``` from collections import deque d = deque(maxlen = 10) print d.maxlen ``` In 2.6 the deque can be used and the maxlen works properly, but maxlen is not an attribute that can be referred to. Cheers