Python使用eval强制转换字符串为字典时报错:File "<string>", line 1, in <module> NameError: name 'nan' is not defined
文本中保存的内容为:
{
'QQQ': [0.067, 0.167, 0.2, 0.033, 0.233, 0.267, 0.1, 0.133],
'TTT': [0.5, 0.375, 0.25, 0.3, 0.6, 0.333, 0.857, 0.636, 0.667, 0.556]
}
用eval转换为字符串时报错:
File "test.py", line 43, in d1
data = eval(infile.readline())
File "<string>", line 1, in <module>
NameError: name 'nan' is not defined
解决:
globals = {
'nan': 0
}
# -----------
data = eval(infile.readline(), globals)
参考资料:
Python中,用eval强制将字符串转换为字典变量时候出错:NameError: name ‘null’ is not defined
Python使用eval强制转换字符串为字典时报错:File "<string>", line 1, in <module> NameError: name 'nan' is not defined的更多相关文章
- python]用eval强制将字符串转换为字典变量时候出错:NameError: name 'null' is not defined[python]用eval函数 字符串转dict
本博客已搬家至个人网站 在路上 - On the way 下面的 技术 分类. 你可以通过点击 更新帖子 [已解决]Python中,用eval强制将字符串转换为字典变量时候出错:NameError: ...
- python使用input()来接受字符串时一直报错“xxx is not defined”
报错信息: “Please input your guess: gussTraceback (most recent call last): File "coinGuessGame.py& ...
- python 列表、元组、字符串、字典、集合、return等梳理
有必要对这些数据类型及操作做下梳理: 1.列表:增删改查 a.查找: >>> names=["zhang","wang","li&q ...
- 配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XXXXX' to ALLOWED_HOSTS,在setting.py中添加‘*”无效的原因
配置python+mod_wsgi+apache 时 在浏览器中访问服务器时报错:Invalid HTTP_HOST header: 'XXXXX'. You may need to add u'XX ...
- Day2 - Python基础2 列表、字符串、字典、集合、文件、字符编码
本节内容 列表.元组操作 数字操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1. 列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作 ...
- python 的 reshape强制转换格式的用途
shu=[[ 0.03046758], [ 0.05485586], [ 0.03282908], [ 0.02107211], [ 0.0391144 ], [ 0.07847244], [ 0.1 ...
- Python中str类型的字符串写入二进制文件时报TypeError错的处理方式
在用二进制模式打开文件情况下,写入一个str对象时报错:TypeError: a bytes-like object is required, not 'str' 出现该问题是因为Python严格区分 ...
- python中使用openpyxl模块时报错: File is not a zip file
python中使用openpyxl模块时报错: File is not a zip file. 最大的原因就是不是真正的 xlsx文件, 如果是通过 库xlwt 新建的文件,或者是通过自己修改后缀名 ...
- python开发学习-day01 (python安装与版本、字符串、字典、运算符、文件)
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
随机推荐
- Kernel Stack Overflow(转)
0x00 漏洞代码 stack_smashing.c #include <linux/init.h> #include <linux/module.h> #include &l ...
- Jarvis OJ-Level3-x64
linux64位ROP技术 #!/usr/bin/env python from pwn import * elf = ELF('level3_x64') Io = remote('pwn2.jarv ...
- Jarvis OJ-Level4
借助DynELF实现无libc的漏洞利用小结 #!/usr/bin/env python # coding:utf-8 from pwn import * elf = ELF('level4') wr ...
- Alert and Action sheets and Timer and Animation
- sscanf的使用
sscanf的使用 语法 int ssanf(const char *buffer, const char *format,[argument]...); 参数 buffer 存储的数据 format ...
- (40)zabbix监控web服务器访问性能
zabbix web监控介绍 在host列可以看到web(0),在以前的版本这项是独立出来的,这个主要实现zabbix对web性能的监控,通过它可以了解web站点的可用性以及性能. 最终将各项指标绘制 ...
- GIMP图像窗口的自定义
具体功能包含:初始缩放比例.空格键按下时触发动作
- Linux下基于LVM调整分区容量大小的方法
Linux下调整分区容量大小的方法(适用于centos6-7) 说明:以下方法均使用centos6.9和centos7.4进行测试. Centos6分区容量调整方法 1.web分区空间不足,新添加一块 ...
- laravel富文本编辑和图片上传
---恢复内容开始--- 首先先找到一个适合的编辑器是胜利的一步,选择wangEditor这个编辑器 地址:http://www.wangeditor.com/ 然后选择下载,我是通过网上学习的,所以 ...
- 一、Numpy库与多维数组
# Author:Zhang Yuan import numpy as np '''重点摘录: 轴的索引axis=i可以理解成是根据[]层数来判断的,0表示[],1表示[[]]... Numpy广播的 ...