【问题标题】:Open big file txt (with) - error process_lines打开大文件 txt (with) - 错误 process_lines
【发布时间】:2021-08-12 02:00:26
【问题描述】:

我正在尝试在 python 中读取一个大文件。

with open("some_big_file.txt") as f:
    for line in f:
        process_lines(line)

但我收到此错误:

NameError: name 'process_lines' 未定义

【问题讨论】:

  • 哈哈你的def process_lines(line) 函数/方法在哪里?它与文件的打开无关,但与它的处理有关......

标签: python text with-statement


【解决方案1】:

试试这个:

with open("some_big_file.txt") as f:
    for line in f.readlines():
        print(line)

这将逐行输出您的文件。那你好像没有process_lines这个函数,那就实现吧。

【讨论】:

    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2017-05-13
    相关资源
    最近更新 更多