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

Python open 函数

  •  
  •   bmcjxhgwy · Mar 30, 2018 · 3444 views
    This topic created in 2973 days ago, the information mentioned may be changed or developed.

    存进 txt 的数据都是 unicode 格式,然后我 f = open("taobao.txt", "a", encoding="utf-8") 为啥这行显示错误,但是删了 encoding="utf-8"显示正确了......

    8 replies    2018-04-02 14:23:31 +08:00
    ballshapesdsd
        1
    ballshapesdsd  
       Mar 30, 2018
    说明不是 utf8 啊。。换 gbk 试试
    bmcjxhgwy
        2
    bmcjxhgwy  
    OP
       Mar 30, 2018
    @ballshapesdsd 不是编码,而是格式问题...直接显示 unexpected arguments ( s )了..我记得以前这么写是可以的
    layorlayor
        3
    layorlayor  
       Mar 30, 2018
    你以前写的是 codecs.open("taobao.txt", "a", encoding="utf-8")???
    bmcjxhgwy
        4
    bmcjxhgwy  
    OP
       Mar 30, 2018
    @layorlayor 以前好像是 python3 版本 这次是 python2 版本
    kunluanbudang
        5
    kunluanbudang  
       Mar 30, 2018 via Android
    2
    3
    这个函数的签名不同,3 有很大的变化
    yuanhego
        6
    yuanhego  
       Mar 30, 2018
    目测如 3 楼所说,楼主把 codecs 模块的 open 函数和内置 open 函数用错了
    NoAnyLove
        7
    NoAnyLove  
       Apr 1, 2018
    至少贴个 traceback 啊。。。。。。
    frostming
        8
    frostming  
       Apr 2, 2018
    Python 2:
    from codecs import open
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3634 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 10:24 · PVG 18:24 · LAX 03:24 · JFK 06:24
    ♥ Do have faith in what you're doing.