gpt4 book ai didi

Python islice 正在读取相同的行

转载 作者:行者123 更新时间:2023-11-28 21:59:55 25 4
gpt4 key购买 nike

<分区>

我有一个很大的日志文件(> 1GB)需要分析,所以我写了一个 python 程序。我使用了 islice,所以我可以分块(10,000 行)读取文件,这样我的服务器就不会耗尽内存。

我在 stackoverflow 上查找了一些 islice 解决方案并实现了一个,但该程序没有按预期工作,因为 isclice 每次都读取相同的行(但在读取整个后正确停止文件...)。我不能使用 with open 因为它带有 python 2.5,我有 python 2.4...

我的代码如下:

    n = 100000;     # n lines
inf = open(fn, "r")
while True:
next_n_lines = list(islice(inf, n))
if not next_n_lines:
break
out_fn = produce_clean_logfile(next_n_lines)
a, t = main(out_fn)
send_log(a,t)

你知道这是怎么回事吗?

提前致谢。此致,约翰。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com