Iver
Iver

Reputation: 33

How do I detect if a bytearray is empty in python?

I need to detect when the bytearray is empty like these two in the middle: 6 bytearrays 2 empty

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

Answers (1)

9769953
9769953

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

Related Questions