1

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")
2
  • 4
    if not my_bytearray: should work fine. Commented Aug 10, 2022 at 10:17
  • if not my_bytearray: print('empty")? Commented Aug 10, 2022 at 10:17

1 Answer 1

2
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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.