Welcome to demofile.txt
This file is for testing purposes.
Good Luck!
以上内容在我的文本文件中
如何从该文本文件读取最后10个字节?预期的输出是:
Good Luck!
答案 0 :(得分:-1)
in_file.seek(-10, 2) # where 2 denotes the reference point being the end of the file
然后:
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)
输出:
b'Good Luck!'