How can I read last 10 bytes from a text file? [closed]

in_file.seek(-10, 2)  # where 2 denotes the reference point being the end of the file

So then:

in_file = open("demofile.txt", "rb") # opening for [r]eading as [b]inary
in_file.seek(-10, 2)
s = in_file.read(10)
print(s)

OUTPUT:

b'Good Luck!'

Leave a Comment