python - python get() 函数为 str 类和类型 str/class int 和 int 类型提供不同的值
问题描述
我正在尝试将 python 2 代码转换为 python 3,并且刚刚知道两个版本上 type() 函数的区别。我基本上是使用熊猫从 json 文件中提取数据。我有一个变量word = 0x00000010.
,我想从 json 文件中获取 word 的值。
所以我的代码在下面
json_data = [Basically this variable have the pulled data from json file]
json_data.get(int(str(word),16), 'none')
给出 python 2 中存在的值,但在 python 3 中它返回nan
. 我假设它与为 python 3 提供类的 type(str(word)) 有关
我已经看到了许多与这种差异相关的问题,但实际上并没有解决我的问题。
json文件格式:
{
"color" : "red",
"sets" :
{
"0x00000010":"yellow",
"0x00000020":"red
}
}
并且 json_data 包含“集合”中的字典
解决方案
推荐阅读
- python - Pandas Dataframe 未在函数中覆盖
- node.js - 尝试使用节点 js、express、ejs 和方法覆盖从猫鼬中删除文档时出现“无法发布”错误消息
- javascript - 使用reduce方法的Javascript转换数组
- loops - 使用带有公差的割线法进行迭代
- css - 使用 CSS 使环的中间透明
- xamarin - 如何区分单击自定义控件
- javascript - 如何迭代地在每个 SVG 元素旁边添加文本
- java - 根据传入的值获取连续值
- r - Using mutate with a stored list of formulas over specified columns
- sql - 如何调整我的 Oracle SQL 查询以更快地运行?