如何清理和计算字节数组?

How to cleanup and count bytearray's?

我有一个bytearray缓冲区:

buffer = bytearray() #creates the buffer

我的数组最大应为 500 字节。

我想要的是:

缓冲区填满 500 字节后,我想清理数组并从头开始追加。

if (buffer.count() >= 500) #ERROR!! count()
  buffer.clean()  #ERROR!! clean?!

buffer.append(10) #appends some value to the array

我知道 this post,但不清楚我怎样才能计算数组中有多少个。 b.count(b'a')

我自己/从评论中找到了答案 - 我可以使用以下内容:

  • len(buffer) # to have the length of the buffer
  • del buffer[:] # for cleaning up the buffer