Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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")
if not my_bytearray:
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.
False
if my_bytearray == b"":
Add a comment
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
if not my_bytearray:should work fine.