【问题标题】:How do I get colab to access a folder in github repository to work on the files inside?如何让 colab 访问 github 存储库中的文件夹以处理其中的文件?
【发布时间】:2021-06-06 08:19:51
【问题描述】:

所以我想使用 colab 来处理我拥有的一些文件,但它存储在 github 上。我宁愿不下载文件或将其放入谷歌驱动器(低存储空间)。如何让 colab 访问我的 repo 中的文件夹,以便循环访问里面的文件或其他东西,并替换它们?

我的新代码在 colab 中会是什么样子? P.S 这是我直接在我的硬盘上工作时使用的代码。

import os
for a in os.listdir(folder):
if a.endswith('.txt'):
print('1')

【问题讨论】:

  • 你可以克隆 repo 吗?类似git clone <repo url>

标签: python-3.x github google-colaboratory


【解决方案1】:

您可以将其存储在 OneDrive 中。为此,您首先需要进行身份验证,然后使用 OneDrive REST API 传递您所追求的文件的位置。 OneDrive's SDK for Python GitHub 页面上记录了有关如何执行此操作的详细信息,并提供了一些示例来帮助您入门。

您也可以使用resquest 库:

>>> import requests
>>> r = requests.get('https://github.com/kennethreitz/requests/blob/master/README.rst')
>>> 'Requests:' in r.text
True
>>> r.headers['Content-Type']
'text/html; charset=utf-8'
>>> r = requests.get('https://raw.github.com/kennethreitz/requests/master/README.rst')
>>> 'Requests:' in r.text
True
>>> r.headers['Content-Type']
'text/plain; charset=utf-8'
>>> print r.text
Requests: HTTP for Humans
=========================


.. image:: https://travis-ci.org/kennethreitz/requests.png?branch=master
[... etc. ...]

还有 git 库可以创建对 git 存储库的对象模型访问。你可以在那个link找到教程。

【讨论】:

    猜你喜欢
    • 2016-04-01
    • 2021-05-10
    • 2022-11-10
    • 2021-05-13
    • 2020-04-21
    • 2023-04-02
    • 2020-10-02
    • 2022-01-09
    • 1970-01-01
    相关资源
    最近更新 更多