1

i have a problem with a string. This is the code:

if x.find("Sensor")!=-1 :

The error that comes out to me is the following:

if x.find("Sensor")!=-1 :
TypeError: argument should be integer or bytes-like object, not 'str'

I think I need to convert the string to binary. Do you have any idea how to do it?

Thank you all

1
  • Seems variable x contains a byte string object. So, you should pass x.find(b"Sensor") byte string as a parameter of the find method. Your current condition will work only on a string. Commented Sep 15, 2021 at 10:45

2 Answers 2

6

It means your string is a bytes object, so try:

if x.find(b"Sensor")!=-1 :
Sign up to request clarification or add additional context in comments.

Comments

2

You need to check if you are analyzing a string or a byte object. If it is a byte object you just decode it, example:

element = b'Content to be searched'
string_element = element.decode('UTF-8')
string_element.find('word you are looking for')

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.