推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
ppj
V2EX  ›  Python

Python 每日一练:大文本文件读取

  •  
  •   ppj · Sep 16, 2022 · 2920 views
    This topic created in 1472 days ago, the information mentioned may be changed or developed.

    大文本文件处理:

    • 利用 open 打开文件,一行一行读

    • 利用 read(size)一块一块的读

    • 利用 readlines 反复读

    • 利用 fileinput 模块进行迭代遍历文件

    查看代码 => 代码

    1 replies  •  2022-09-16 10:57:33 +08:00
    sairoa
        1
    sairoa  
       Sep 16, 2022
    这么处理速度太慢,起一个进程专门读文件,一行一行的把内容传到队列里,然后视情况再起若干数据处理进程,处理完送到队列,再起一个进程进行结果输出。

    写完才发现只是读文件啊。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2683 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    ♥ Do have faith in what you're doing.