相关疑难解决方法(0)

如何在Python中廉价地获得行数?

我需要在python中获取大文件(数十万行)的行数.记忆和时间方面最有效的方法是什么?

目前我这样做:

def file_len(fname):
    with open(fname) as f:
        for i, l in enumerate(f):
            pass
    return i + 1
Run Code Online (Sandbox Code Playgroud)

有可能做得更好吗?

python text-files line-count

931
推荐指数
18
解决办法
77万
查看次数

如何在python中检查文件大小?

我正在Windows中编写Python脚本.我想根据文件大小做一些事情.例如,如果大小大于0,我将向某人发送电子邮件,否则继续其他事情.

如何检查文件大小?

python file

684
推荐指数
8
解决办法
57万
查看次数

标签 统计

python ×2

file ×1

line-count ×1

text-files ×1