使用 Python/Jython 复制范围内的行

发布于 2024-09-24 01:15:19 字数 192 浏览 0 评论 0原文

我有一个不断更新的服务器日志文件。 在执行一些脚本之后,我想将执行的相关部分从服务器日志收集到执行日志中。

基本上,我需要在测试开始之前捕获服务器日志的最后行号(我已经知道如何做),比如 X,然后在执行后,将行从 X 复制到新的服务器日志结束,现在,X+1000。

如何仅复制 X 行到 X+1000 行?

谢谢,阿萨夫

I have a server log file which is constantly updated.
after some script execution, I want to collect the relevant part of my execution from the server log into an execution log.

Basically, I need to capture the last line number of my server log before the test started (which I already know how to do), say X, and after execution, copy the lines from X to the new end of server log, now, X+1000.

How do I copy only lines X to X+1000?

Thanks, Assaf

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阪姬 2024-10-01 01:15:19

试试这个

open("execution.log", "w").write("\n".join(open("server.log").readlines()[X:X+1000]))

Try this

open("execution.log", "w").write("\n".join(open("server.log").readlines()[X:X+1000]))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文