python 2.7版本解决TypeError: 'encoding' is an invalid keyword argument for this function
今天在用yaml处理数据时,由于yaml.load可接收一个byte字符串,unicode字符串,打开的二进制文件或文本文件对象,但字节字符串和文件必须是utf-8,utf-16-be或utf-16-le编码的。因此读取数据的时候用了
data_file = open("F:\\MyPro\\data.yaml", "r", encoding='utf-8')
运行的时候报错:TypeError: 'encoding' is an invalid keyword argument for this function
网上查找一番后,改成如下这样就可以搞定
import io
data_file = io.open("F:\\MyPro\\data.yaml", "r", encoding='utf-8')
python 2.7版本解决TypeError: 'encoding' is an invalid keyword argument for this function的更多相关文章
- TypeError: 'encoding' is an invalid keyword argument for this function 解决Python 2.7
在python2.7中这样调用代码 open('file/name.txt','r',encoding= 'utf-8').read() 会出现 TypeError: 'encoding' is an ...
- TypeError: 'encoding' is an invalid keyword argument for this function
python 2.7 问题 data_file = open("F:\\MyPro\\data.yaml", "r", encoding='utf-8') 运行 ...
- python TypeError: ‘encoding’ is an invalid keyword argument for this function
shell调用python脚本出现了这个问题,查询原因得知,python脚本是python3.6写的,我们服务器上默认的python是python2.7.3,所以会出现编码问题. 解决思路: 1.安装 ...
- TypeError: 'newline' is an invalid keyword argument for this function 错误解决
出错代码: outputFile = open('output1.csv', 'w', newline='') # error line outputWriter = csv.writer(outpu ...
- Python pika, TypeError: exchange_declare() got an unexpected keyword argument 'type' 问题修复
网上很多写法都是 type='fanout' 这样的.(这里是基于python=3.6版本, pika=0.13.0 版本) credentials = pika.PlainCredentials(' ...
- TypeError: __init__() got an unexpected keyword argument 'serialized_options'
问题描述: TypeError: __init__() got an unexpected keyword argument 'serialized_options' File "objec ...
- 关于Jupyter Notebook无法自动补全(Autocompletion),报错TypeError: __init__() got an unexpected keyword argument 'column' 的解决方案
关于Jupyter Notebook无法自动补全(Autocompletion),报错TypeError: __init__() got an unexpected keyword argument ...
- TypeError: parse() got an unexpected keyword argument 'transport_encoding'
错误: TypeError: parse() got an unexpected keyword argument 'transport_encoding'You are using pip vers ...
- TypeError: while_loop() got an unexpected keyword argument 'maximum_iterations'
错误: TypeError: while_loop() got an unexpected keyword argument 'maximum_iterations' 参照https://blog.c ...
随机推荐
- (转)yi_meng linux 下 ifcfg-eth0 配置 以及ifconfig、ifup、ifdown区别
linux 下 ifcfg-eth0 配置 以及ifconfig.ifup.ifdown区别 原文:https://www.cnblogs.com/yi-meng/p/3214471.html这3个命 ...
- Python3基础(5)常用模块:time、datetime、random、os、sys、shutil、shelve、xml处理、ConfigParser、hashlib、re
---------------个人学习笔记--------------- ----------------本文作者吴疆-------------- ------点击此处链接至博客园原文------ 1 ...
- cucumber的hooks
引用链接:https://github.com/cucumber/cucumber/wiki/Hooks Hooks Cucumber provides a number of hooks which ...
- Android入门:Service入门介绍
一.Service介绍 Service类似于Windows中的服务,没有界面,只是在后台运行:而服务不能自己运行,而是需要调用Context.startService(Intent intent);或 ...
- 【Java】深入理解Java中的spi机制
深入理解Java中的spi机制 SPI全名为Service Provider Interface是JDK内置的一种服务提供发现机制,是Java提供的一套用来被第三方实现或者扩展的API,它可以用来启用 ...
- 构建第一个Spring Boot2.0应用之集成mybatis、Druid(七)
一.环境: IDE:IntelliJ IDEA 2017.1.1 JDK:1.8.0_161 Maven:3.3.9 springboot:2.0.2.RELEASE 二.说明: 本文综合之 ...
- [转]ubuntu16.04安装teamviewer12依赖包解决
安装teamviewer下载地址:http://www.teamviewer.com/en/download/linux/ 下载的是:teamviewer_12.0.76279_i386.deb ...
- 将ts文件合并为mp4命令
cmd: copy/b D:\*.ts D:\new.ts 参考:http://blog.sina.com.cn/s/blog_66b4f1180102uzxs.html
- ABAP Netweaver和Cloud Foundry上的环境变量Environment Variable
Netweaver 更准确的说应该是系统变量:结构体sy 设一个断点,调试器里看这些字段的值就能知道每个字段是用来做什么的. sy-dbsys sy-sysid sy-opsys sy-saprl s ...
- POJ 2718 Smallest Difference(dfs,剪枝)
枚举两个排列以及有那些数字,用dfs比较灵活. dfs1是枚举长度短小的那个数字,dfs2会枚举到比较大的数字,然后我们希望低位数字的差尽量大, 后面最优全是0,如果全是0都没有当前ans小的话就剪掉 ...