如何将此代码从 2.5 移植到 3.4 版本?
from __future__ import with_statement
from ..globals import addonPath
import os, time
import collections
class TailDeque(collections.deque):
'''Implementation of deque with limited maxlen support for Python 2.5.'''
def __init__(self, iterable=None, maxlen=20):
super(TailDeque, self).__init__([])
self.maxlen = maxlen
if iterable is not None:
self.extend(iterable)
def extend(self, iterable):
for item in iterable:
self.append(item)
def extendleft(self, iterable):
for item in iterable:
self.appendleft(item)
def appendleft(self, item):
if len(self) == self.maxlen:
self.pop()
super(TailDeque, self).appendleft(item)
def append(self, item):
if len(self) == self.maxlen:
self.popleft()
super(TailDeque, self).append(item)
logPath = os.path.join( addonPath, "log.txt" )
logQueue = TailDeque()
def log(text):
return
logQueue.append(time.strftime("%H:%M:%S") + " - " + text)
with open(logPath, "w") as fs:
fs.write('\n'.join(logQueue))
第 10 行:self.maxlen = maxlen
AttributeError:“collections.deque”对象的属性“maxlen”不可写