Post

PythonPython

L
Lakshmi sowjanya

Posted on 5th March 2024|59 views

0
votes

Typeerror A Bytes-like Object Is Required Not Str

How to resolve the error typeerror a bytes-like object is required not str in python?

here is my code which is throwing an error called a bytes-like object is required not str please help me out

for line in lines: 

print(type(line))# <class of 'bytes'> 

if 'substring' in line: 

print('successful')

 

Answers
P
veerubhotla sowmithri

Posted on 5th March 2024

You have to use decode() try this

for line in lines: 

line = line.decode() 

print(type(line))# <class of 'str'> 

if 'substring' in line: 

print('successful')

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos