简体   繁体   English

如何访问 google.colab 中 object 中的每个元素?

[英]How to access each element in object in google.colab?

I uploaded a file in googl colab and I tried to get the name of the file我在 googl colab 中上传了一个文件,我试图获取文件的名称

This is a result when I print upload.keys() :这是我打印upload.keys()时的结果:

dict_keys(['SSE.csv', 'SSE_origin.csv'])

I tried to access each element of object.我试图访问 object 的每个元素。 I only find this solution.我只找到这个解决方案。

from google.colab import files

uploaded = files.upload()

for name in uploaded.keys():
    print(name)

Is there any other solution like indexing?有没有像索引这样的其他解决方案?

The problem is that you have a dict_keys object, not a list.问题是你有一个dict_keys object,而不是一个列表。 To use it as a list you have to convert it:要将其用作列表,您必须对其进行转换:

list(uploaded.keys())

Now you can access each element by indexing现在您可以通过索引访问每个元素

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

相关问题 在 Google.colab 中安装 Openpyxl - Openpyxl installation in Google.colab 如何解决 ModuleNotFoundError:没有名为“google.colab”的模块 - How to resolve ModuleNotFoundError: No module named 'google.colab' 在 Pycharm 中寻找 google.colab 替代品 - Looking for a google.colab substitute in Pycharm google.colab 模块中是否有 function 来关闭运行时 - Is there a function in google.colab module to close the runtime 从 google.colab 导入文件,如何在 Jupyterlab 中获取文件的相同行为 - from google.colab import files, how to get the same behaviour of files in Jupyterlab 如何使用 google.colab 导入文件上传文本文件,然后将其转换为一组单词? - How to upload a text file using google.colab import files and then converting it into a set of words? 在 VM 引擎中导入 google.colab 不会让我在 Google Colab 中运行 Jupyter Notebook? - Importing google.colab in VM Engine Doesn't Let me Run Jupyter Notebook in Google Colab? Google Colab:如何访问图像? - Google Colab: How to access Images? 使用google.colab导入文件在Google collab上的协作者无法获得的数据 - Data unavailable to Collaborators on google collab using google.colab import files pip 安装了 google.colab,现在无法在 Jupyter 笔记本上运行代码 - pip installed google.colab and now unable to run code on Jupyter notebook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM