V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2022-09-16 08:57:55 +08:00 · 1699 次点击
    这是一个创建于 587 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大文本文件处理:

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

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

    • 利用 readlines 反复读

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

    查看代码 => 代码

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

    写完才发现只是读文件啊。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3279 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:02 · PVG 21:02 · LAX 06:02 · JFK 09:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.