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

Python open 问题

  •  
  •   xiaomacai · 2017-06-21 15:33:15 +08:00 · 1417 次点击
    这是一个创建于 2493 天前的主题,其中的信息可能已经有所发展或是发生改变。

    with open('comments.txt', 'r') as f:

     for line in f.readlines():
     
     line = line.strip()
               
     res_list.append(json.loads(line))
    

    代码入如上 问题: shell 里执行上面脚本能够读取整个文件内容,但是在 cronab 里面只能读取最后两行。问题比较诡异。

    第 1 条附言  ·  2017-06-21 16:25:02 +08:00
    问题已经解决,确实是路径问题。
    3 条回复    2017-06-21 16:51:47 +08:00
    kimchan
        1
    kimchan  
       2017-06-21 15:43:55 +08:00
    确定 shell 和 crontab 读到的是同一个文件吗? 有没有用绝对路径试试.
    scriptB0y
        2
    scriptB0y  
       2017-06-21 15:45:53 +08:00
    楼上说的对,写在 cron 里的都要写绝对路径(包括 python 的路径),另外发帖之前先预览一下,代码格式化没写好
    xiaomacai
        3
    xiaomacai  
    OP
       2017-06-21 16:51:47 +08:00
    @scriptB0y
    @kimchan

    确实是因为路径问题,感谢。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1469 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:59 · PVG 07:59 · LAX 16:59 · JFK 19:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.