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
zenomac
V2EX  ›  Python

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

  •  
  •   zenomac · 2012-08-21 10:37:31 +08:00 · 2768 次点击
    这是一个创建于 4258 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如
    open_file.readlines().index('thestring')或者var=open_file.readlines()

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

    不太理解.
    2 条回复    1970-01-01 08:00:00 +08:00
    ratazzi
        1
    ratazzi  
       2012-08-21 10:42:31 +08:00   ❤️ 1
    毕竟是文件读取操作,读取之后指针会移动的
    0bit
        2
    0bit  
       2012-08-21 10:48:04 +08:00
    楼上正解
    想回到文件头部重新开始读取的话,用open_file.seek(0)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   932 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:40 · PVG 05:40 · LAX 14:40 · JFK 17:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.