推荐学习书目
› 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
sjmcefc2
V2EX  ›  Python

如何直接删除文本中某一行?

  •  
  •   sjmcefc2 · May 20, 2018 · 3206 views
    This topic created in 3113 days ago, the information mentioned may be changed or developed.

    想通过 mmap 读取文件中的行,然后直接读写该文本删除某些特定的行。 怎么实现呢?

    7 replies  •  2018-05-21 13:10:22 +08:00
    afpro
    afpro
    May 21, 2018 via Android
    1
    不能
    sjmcefc2
    sjmcefc2
    OP
    May 21, 2018
    2
    貌似还是只有重写文件这一个办法?
    cfwyy
    cfwyy
    May 21, 2018
    3
    就为了删除文本某一行?为何不直接用 sed?
    mypchas6fans
    mypchas6fans
    May 21, 2018
    4
    sed/awk 教做人
    laike9m
    laike9m
    May 21, 2018
    5
    mmap 可能不行,fileinput 是可以做到的,把 inplace=True 即可
    laike9m
    laike9m
    May 21, 2018
    6
    不过 fileinput 好像还是得遍历一遍……效率也不高
    weyou
    weyou
    May 21, 2018
    7
    从文件系统来看任何方法都不可避免的要重写文件。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1389 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 17:14 · PVG 01:14 · LAX 09:14 · JFK 12:14
    ♥ Do have faith in what you're doing.