On Fri, Nov 30, 2018 at 02:19:25AM +0530, srinivasan wrote:
> Dear Mats,
> 
> Thanks a lot for your quick responses, again the below line seems to
> be throwing the same error, is that should I again decode the line
> where am facing the issue to str? or could you please let me if there
> is any alternative solution for the same or workaround in python 3.6?

You don't need a "workaround", you need to fix the bug in your code:


> Traceback (most recent call last):
> , in parse_device_info
>     string_valid = not any(keyword in info_string for keyword in block_list)
>   File "/home/srinivasan/Downloads/bt_tests/qa/test_library/bt_tests.py",
> line 52, in <genexpr>
>     string_valid = not any(keyword in info_string for keyword in block_list)
> TypeError: a bytes-like object is required, not 'str'

You get that error when you wrongly try to test for a string inside a 
bytes object:

py> 'string' in b'bytes'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'


You fix that by making sure both objects are strings, or both are bytes, 
which ever is better for your program:

py> 'a' in 'abc'  # string in string is okay
True
py> b'a' in b'abc'  # bytes in bytes is okay
True

py> 'a' in b'abc'  # string in bytes is NOT OKAY
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'

py> b'a' in 'abc'  # bytes in string is NOT OKAY
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'in <string>' requires string as left operand, not bytes


Don't mix strings and bytes. It won't work.


-- 
Steve
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to