Reputation: 33
I need to detect when the bytearray is empty like these two in the middle:
I am quite new to coding so I have tried this, but it doesnt detect when its for a bytearray:
if my_bytearray == "":
print("Read drop out")
Upvotes: 1
Views: 3112
Reputation: 12221
if not my_bytearray:
print("Read drop out")
should work fine.
The mistake in your code is that you compare a bytearray to a string; that is always False
. if my_bytearray == b"":
would have worked. But the solution above tends to be more Pythonic and more used.
Upvotes: 2