Python 如何从文本文件中读取最后10个字节?

Python 如何从文本文件中读取最后10个字节?,python,Python,以上内容在我的文本文件中 如何从该文本文件中读取最后10个字节?预期产出为: Welcome to demofile.txt This file is for testing purposes. Good Luck! 那么: in_file.seek(-10, 2) # where 2 denotes the reference point being the end of the file 输出: in_file = open("demofile.txt", "rb") # openin

以上内容在我的文本文件中

如何从该文本文件中读取最后10个字节?预期产出为:

Welcome to demofile.txt
This file is for testing purposes.
Good Luck!
那么:

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)

可能是重复的,它帮助我@user5126最后10个字节@KenY-N为此进行了编辑。
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!'