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

将readlines()作为list操作一次之后 为什么会自动清空

  •  
  •   zenomac · Aug 21, 2012 · 3502 views
    This topic created in 5038 days ago, the information mentioned may be changed or developed.
    比如
    open_file.readlines().index('thestring')或者var=open_file.readlines()

    然后open_file.readlines()返回的都是空列表

    不太理解.
    2 replies    1970-01-01 08:00:00 +08:00
    ratazzi
        1
    ratazzi  
       Aug 21, 2012   ❤️ 1
    毕竟是文件读取操作,读取之后指针会移动的
    0bit
        2
    0bit  
       Aug 21, 2012
    楼上正解
    想回到文件头部重新开始读取的话,用open_file.seek(0)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:45 · PVG 13:45 · LAX 22:45 · JFK 01:45
    ♥ Do have faith in what you're doing.