Array? Please help.

Scott David Daniels scott.daniels at
Sun May 28 19:52:25 CEST 2006

Dr. Pastor wrote:
> Scott David Daniels wrote:
>> Dr. Pastor wrote:
>>> I need a row of 127 bytes that I will use as a
>>> circular buffer. Into the bytes (at unspecified times)
>>> a mark (0<mark<128) will be written, one after the other.
>>> After some time the "buffer" will contain the last 127 marks.
>> Sounds a lot like homework.
> No it is not home work.

OK, taking you at your word, here's one way:

     class Circular(object):
         def __init__(self):
    = array.array('b', [0] * 127)
             self.point = len( - 1

         def mark(self, value):
             self.point += 1
             if self.point >= len(
                 self.point = 0
   [self.point] = value

         def recent(self):
             result =[self.point :] +[: self.point]
             for n, v in enumerate(result):
                 if v:
                     return result[n :]
             return result[: 0] # an empty array
--Scott David Daniels
scott.daniels at

More information about the Python-list mailing list