python-3.x - 如何访问从 kaggle 下载到 Colaboratory notebook 的文件?
问题描述
我在操作 Colaboratory Notebook 中的多个文件时遇到了一些困难,该笔记本下载到我的谷歌驱动器中的 /content 目录。到目前为止,我已经使用以下代码成功下载并提取了一个 kaggle 数据集到 Colaboratory Notebook:
!kaggle datasets download -d iarunava/cell-images-for-detecting-malaria -p /content
!unzip \cell-images-for-detecting-malaria.zip
我还能够使用 Pillow 将数据集中的单个文件导入到我的 Colaboratory 会话中(我从提取过程中产生的输出中获得了文件名):
from PIL import Image
img = Image.open('cell_images/Uninfected/C96P57ThinF_IMG_20150824_105445_cell_139.png')
如何在不事先知道名称的情况下从 /content 访问多个提取的文件?
谢谢!
解决方案
经过一些进一步的实验,我发现 python os 模块在 Colab Notebooks 中的工作方式与在个人计算机上的工作方式相似。例如,在 Colab Notebook 中,命令
os.getcwd()
返回 '/content' 作为输出。
此外,该命令os.listdir()
返回我下载和提取的所有文件的名称。
推荐阅读
- sql-server - 使用 GitHub 上 Geral2 使用 API Consumer 的 SQL 过程的 Accept 元素的 API 调用标头问题
- node.js - 在单个 Azure 应用程序中使用 Express 后端反应应用程序(通过 create-react-app)?
- javascript - 如何在单击反应原生的父文件中的图标时专注于子文件中的文本字段?
- android - 从firebase检索到recyclerview时图像不出现
- java - 有没有办法遍历 ListView 的所有子视图并将它们转换为 TextView
- google-apps-script - 在 Google Apps 脚本的自定义函数中添加前导零
- powershell - 如何阻止 PSReadLine 在 powershell 7.1.3 中更改光标?
- javascript - 使用纯 javascript 从外部网站获取信息
- ios - SFDC - 使用 Forcereact 反应本机项目 - 不工作
- javascript - Break 语句不起作用。它返回答案 50 两次。一旦条件为真并第一次打印,有没有办法突破?