示例文件 `go.mod`: module daily/gui go 1.20 require ( github.com/ncruces/zenity v0.10.10 gocv.io/x/gocv v0.33.0 ) require ( github.com/akavel/rsrc v0.10.2 // indirect github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect github.com/josephspurrier/goversioninfo v1.4.0 // indirect github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect github.com/stretchr/testify v1.8.0 // indirect golang.org/x/image v0.12.0 // indirect golang.org/x/sys v0.12.0 // indirect ) 示例代码: import os def readlines_reverse(filename): with open(filename, "r", encoding="utf-8") as f: f.seek(0, os.SEEK_END) # move to end of file position = f.tell() line = "" while position >= 0: f.seek(position) # move back one character next_char = f.read(1) if next_char == "\n": yield line[::-1] line = "" else: line += next_char position -= 1 yield line[::-1] if __name__ == "__main__": for line in readlines_reverse("./go.mod"): print(line) 结果: ) golang.org/x/sys v0.12.0 // indirect golang.org/x/image v0.12.0 // indirect github.com/stretchr/testify v1.8.0 // indirect github.com/randall77/makefat v0.0.0-20210315173500-7ddd0e42c844 // indirect github.com/josephspurrier/goversioninfo v1.4.0 // indirect github.com/dchest/jsmin v0.0.0-20220218165748-59f39799265f // indirect github.com/akavel/rsrc v0.10.2 // indirect require ( ) gocv.io/x/gocv v0.33.0 github.com/ncruces/zenity v0.10.10 require ( go 1.20 module daily/gui