How can access Uploaded File in Google colab
10,523
Here's an adjustment to your snippet that will save any uploaded file in the current directory using the uploaded file name.
from google.colab import files
uploaded = files.upload()
for name, data in uploaded.items():
with open(name, 'wb') as f:
f.write(data)
print ('saved file', name)
Author by
hdiz
Updated on June 09, 2022Comments
-
hdiz almost 2 years
I'm new in python and I use
Google Colab
. I uploaded atrain_data.npy
into google Colab and then I want to use it . According to this link How to import and read a shelve or Numpy file in Google Colaboratory?when i run my code i face this error :
TypeError: 'dict_keys' object does not support indexing
Here is my code :
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]])
Thanks