如何清理和计算字节数组?
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
- 如何计算当前数组大小?
count()
需要一个参数,但在这个例子中,应该是什么?
我知道 this post,但不清楚我怎样才能计算数组中有多少个。 b.count(b'a')
- 如何清理数组?或者如何将 "pointer" 再次设置为数组的开头?
我自己/从评论中找到了答案 - 我可以使用以下内容:
len(buffer) # to have the length of the buffer
del buffer[:] # for cleaning up the buffer
我有一个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')
- 如何清理数组?或者如何将 "pointer" 再次设置为数组的开头?
我自己/从评论中找到了答案 - 我可以使用以下内容:
len(buffer) # to have the length of the buffer
del buffer[:] # for cleaning up the buffer