I've very recently migrated to Py 3.5. This code was working properly in Python 2.7:
with open(fname, 'rb') as f:
lines = [x.strip() for x in f.readlines()]
for line in lines:
tmp = line.strip().lower()
if 'some-pattern' in tmp: continue
# ... code
After upgrading to 3.5, I'm getting the:
TypeError: a bytes-like object is required, not 'str'
error on the last line (the pattern search code).
I've tried using the .decode()
function on either side of the statement, also tried:
if tmp.find('some-pattern') != -1: continue
- to no avail.
I was able to resolve almost all 2:3 issues quickly, but this little statement is bugging me.
result = requests.get
and I attempt tox = result.content.split("\n")
. I am a little confused by the error message because it seems to imply thatresult.content
is a string and.split()
is requiring a bytes-like object..?? ( "a bytes-like object is required, not 'str"').. – user4805123