json.dump(list,f)继续在Google Colab上加载

时间:2020-07-16 15:27:25

标签: python json google-colaboratory

我正在尝试在Google Colab上执行以下json.dump操作。但是,每次卡住并仅继续处理此行。如何在Google Colab中解决此问题?

with open(fullpath, 'w') as f:
    json.dump(list, f)

编辑:添加完整的代码:

import generate_gt_from_txt_l
import generate_gt_from_xml_l

#We've shown words are identical for txt and xml so don't do both
import generate_gt_from_txt_w

import load_set
import json
import os

if __name__ == "__main__":
    sets = load_set.load()
    set_names = ['training', 'val1', 'val2', 'test']

    generators = [generate_gt_from_txt_l, generate_gt_from_xml_l, generate_gt_from_txt_w]
    gen_paths = ['lines/txt', 'lines/xml', 'words']

    for s_name, s in zip(set_names, sets):
        for g_path, g in zip(gen_paths, generators):
            fullpath = os.path.join("raw_gts", g_path, s_name+'.json')
            try:
                os.makedirs(os.path.dirname(fullpath))
            except:
                pass
            print(type(g.get_gt(s)))
            with open(fullpath, 'w') as f:
                json.dump(g.get_gt(s), f)
            print(fullpath)

当我在系统上运行代码时,代码运行良好。这只会导致Colab出现问题。

1 个答案:

答案 0 :(得分:-1)

尝试更改变量list的名称:list已被Python使用