【发布时间】:2017-03-15 18:11:37
【问题描述】:
我无法从 json API 中提取数据。我正在尝试获取“Total_allele_count”。我能够从 API 中提取其他数据,但是当涉及到“exac”数据时它不起作用。
"alterations" : [
{
"Gene_position" : "3164,,,",
"exac" : {
"close_matches" : [],
"exact_matches" : [
{
"exac_allele" : [
{
"West_allele_count" : 0,
"Total_allele_count" : "52413,1",
"Male_allele_count" : "11142,0"
这就是失败的地方。我是不是在看东西?
row = alter(data, 'exac', 'Total_allele_count', row)
我的方法
def alter(source, org, allele, fileRow):
try:
toAppend = [int(x) for x in source['alterations'][0][org]['exact_matches'][0][allele].split('/')]
#fileRow.append(str(len(toAppend)))
fileRow.append(toAppend[1]/sum(toAppend))
except:
fileRow.append('N/A')
return fileRow
【问题讨论】:
-
你的json不完整。
-
“不工作”定义不够明确,无法提供分析。当你说“这就是失败的地方”时......你确定吗?你怎么知道的?我怀疑裸露的
except:隐藏了一些有趣的回溯,可用于发现问题所在......