如何从Google Colab中的.yaml文件读取数据

时间:2020-04-05 15:05:21

标签: python-3.x dictionary yaml google-colaboratory

我正在尝试从本地计算机上的.yaml文件中读取数据。但是,当我导入文件并打印数据时,它位于一行中。供参考的屏幕快照在这里:

enter image description here

但是,通过使用Jupiter笔记本,我能够以所需的字典格式成功读取数据。截图供参考

enter image description here

如何在Colab中按行字典格式读取数据?

2 个答案:

答案 0 :(得分:0)

根据the docs

files.upload返回上载文件的字典。

所以你需要做

uploaded = files.upload()
for key, value in uploaded.items():
  data = yaml.load(value)
  print(key)  # prints the file name
  print(data) # prints the loaded data

答案 1 :(得分:0)

尝试一下

data = yaml.load(data["ipl_match.yaml"])