I have a gz file sample.gz.
This is first line of sample gz file.
This is second line of sample gz file.
I read this .gz file and then split it line by line. Once I have individual lines I further split it into parts with whitespace as separator.
import gzip
logfile = "sample.gz"
with gzip.open(logfile) as page:
for line in page:
string = line.split(" ")
print(*string, sep = ',')
I am expecting output like
This,is,first,line,of,sample,gz,file.
This,is,second,line,of,sample,gz,file.
But insted of the above result, I am receiving TypeError:
TypeError: a bytes-like object is required, not 'str'
Why is the split function not working as it is supposed to?