Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法为 Python 2.2 反向读取文本文件?感谢您的帮助 =)
尝试以下。
# method not using the `reverse` function def read_file_reversed(filename): return open(filename, 'r').readlines()[::-1]
它使用切片反转列表。 请注意,这些会将整个文件加载到内存中。