2016-01-07 21 views
-1

我有一個bytearray緩衝液:如何清理和計數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 
  • 我怎麼能算當前數組的大小? count()需要一個參數,但在這個例子中,應該是什麼?

我知道this post,但不清楚我該如何計算我的陣列中有多少人。 b.count(b'a')

  • 如何清理陣列?或者我怎樣才能設置「指針」再次在數組的開始?
+3

怎麼樣'LEN(緩衝)'和'buffer.clear ()'? – vaultah

回答

0

,我發現自己的答案/從註釋 - 我可以使用以下命令:

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