logo-MindMajix
PostPythonPython
L
Lakshmi sowjanya

Posted on 24th July 2024|63 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')

 

1 answers
Answers
P
veerubhotla sowmithri

Posted on 24th July 2024| views

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
Name
Course *
Email *
Phone Number