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

Python open 函数

  •  
  •   bmcjxhgwy · 2018-03-30 16:11:39 +08:00 · 2537 次点击
    这是一个创建于 2191 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    8 条回复    2018-04-02 14:23:31 +08:00
    ballshapesdsd
        1
    ballshapesdsd  
       2018-03-30 16:14:46 +08:00
    说明不是 utf8 啊。。换 gbk 试试
    bmcjxhgwy
        2
    bmcjxhgwy  
    OP
       2018-03-30 16:18:05 +08:00
    @ballshapesdsd 不是编码,而是格式问题...直接显示 unexpected arguments ( s )了..我记得以前这么写是可以的
    layorlayor
        3
    layorlayor  
       2018-03-30 16:23:44 +08:00
    你以前写的是 codecs.open("taobao.txt", "a", encoding="utf-8")???
    bmcjxhgwy
        4
    bmcjxhgwy  
    OP
       2018-03-30 16:26:10 +08:00
    @layorlayor 以前好像是 python3 版本 这次是 python2 版本
    kunluanbudang
        5
    kunluanbudang  
       2018-03-30 18:11:56 +08:00 via Android
    2
    3
    这个函数的签名不同,3 有很大的变化
    yuanhego
        6
    yuanhego  
       2018-03-30 18:28:23 +08:00
    目测如 3 楼所说,楼主把 codecs 模块的 open 函数和内置 open 函数用错了
    NoAnyLove
        7
    NoAnyLove  
       2018-04-01 12:14:14 +08:00
    至少贴个 traceback 啊。。。。。。
    frostming
        8
    frostming  
       2018-04-02 14:23:31 +08:00
    Python 2:
    from codecs import open
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2797 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:55 · PVG 20:55 · LAX 05:55 · JFK 08:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.