def mrlines(fname, sp='\n'): f = open(fname).read().split(sp) while f != [] and f[-1] == '': f = f[:-1] return f
时间: 2024-05-24 14:10:52 浏览: 141
fname=Client.rar_FastMsg_开源
This function reads the contents of a file with the given filename (fname) and splits it into a list of lines using the separator sp (defaulting to newline character). It then removes any empty lines at the end of the file and returns the resulting list of lines.
For example, if the file "example.txt" contains the following lines:
Hello World
This is an example file.
The function call mrlines("example.txt") would return the list ['Hello World', 'This is an example file.'].
阅读全文