繁体   English   中英

尝试从 google colab 下载文件 - 显示索引错误

[英]Trying to download a file from google colab - Showing index error

from google.colab import files

filename= os.listdir('/content/Real-ESRGAN/results')

files.download('/content/Real-ESRGAN/results/'+filename[0])

显示此错误消息

IndexError                                Traceback (most recent call last)
<ipython-input-5-9cd613c11ac6> in <module>()
      4 
      5 filename= os.listdir('/content/Real-ESRGAN/results')
----> 6 files.download('/content/Real-ESRGAN/results/'+filename[0])

IndexError: list index out of range

可能发生的是您的filename列表为空。 因此,它在索引 0 处没有元素,因此您的索引超出范围。

此代码完美运行:

for i in os.listdir('/content/youfolder') :    
#print(i) 
files.download('/content/youfolder/'+i)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM