您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在python 2.x中是否不可避免出现“编码是无效关键字”错误?

在python 2.x中是否不可避免出现“编码是无效关键字”错误?

对于Python2.7,请io.open()在两个位置使用。

import io
import shutil

with io.open('/etc/passwd', encoding='latin-1', errors='ignore') as source:
    with io.open('/tmp/goof', mode='w', encoding='utf-8') as target:
        shutil.copyfileobj(source, target)

上面的程序在我的电脑上运行没有错误

python 2022/1/1 18:47:29 有314人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶