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

请问如何实现 open pickle 文件后先读后写?

  •  
  •   dwjgwsm · May 16, 2018 · 2906 views
    This topic created in 3056 days ago, the information mentioned may be changed or developed.

    open rb+ 是可以先读后写,调试程序的时候才发现,不能在结合使用 pickle 的时候先读后写,写的时候会抛出错误.那么如何实现先读后 覆盖写 呢?

    一小段测试代码: http://chuantu.biz/t6/311/1526454143x-1404795577.jpg

    5 replies  •  2018-05-18 18:06:12 +08:00
    jmc891205
        1
    jmc891205  
       May 16, 2018
    写到一个临时文件 确定写入成功之后把临时文件覆盖原文件
    dwjgwsm
        2
    dwjgwsm  
    OP
       May 16, 2018
    要这么操作才行啊
    dwjgwsm
        3
    dwjgwsm  
    OP
       May 16, 2018
    如果要这样,那还不如 open 二次 第一次读 第二次写
    lieh222
        4
    lieh222  
       May 17, 2018   ❤️ 1
    pickle.dump(fh)是啥意思,缺失参数吧,dump(obj, file, protocol=None)
    dwjgwsm
        5
    dwjgwsm  
    OP
       May 18, 2018
    @lieh222 原来是语法写错了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2707 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 08:49 · PVG 16:49 · LAX 01:49 · JFK 04:49
    ♥ Do have faith in what you're doing.