I suppose read()
does read a file as a string, while readline()
reads a file line by line. There's a size positional argument for the two method which default to -1 (read everything). Now my problem begins, isn't x.read() == x. readlines()
since both defaults to -1 which reads everything?
Here's my code:
with open('some_file.png') as my_file:
check = my_file.read()
print(b'\x89PNG\r\n\x1a\n' in check) #all PNG files has the byte string. #This returned True
check = my_file.readlines()
print(b'\x89PNG\r\n\x1a\n' in check) #this one returned False
I thought both should return True since I read everything without sizing. A good explanation would help. Thanks