我是python中的新手,我使用 Google Colab
. 我上传了一个 train_data.npy
到谷歌Colab然后我想用它 . 根据这个链接How to import and read a shelve or Numpy file in Google Colaboratory?
当我运行我的代码我面临这个错误:
TypeError:'dict_keys'对象不支持索引
这是我的代码:
uploaded = files.upload()
for fn in uploaded.keys():
print('User uploaded file "{name}" with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
with open('train_data.npy', 'w') as f:
f.write(uploaded[uploaded.keys()[0]])
谢谢
1 回答
这是对您的代码段的调整,它将使用上传的文件名保存当前目录中的所有上传文件 .