【问题标题】:Getting a file path from GitHub从 GitHub 获取文件路径
【发布时间】:2021-10-28 20:54:22
【问题描述】:

我的 Google colab 中有以下代码,它给了我错误消息:

FileNotFoundError: [Errno 2] 没有这样的文件或目录:

代码:

!pip install arff    
import arff
uploaded = arff.load(open('https://github.com/userName/repoName/blob/combination_of_nums_and_letters/file_name.arff'))

我通过点击 GitHub 中的“复制永久链接”获得了文件路径。

这是我得到的路径的问题吗?还是我的代码?如果路径错误,我怎样才能获得正确的路径以使该代码正常工作?

【问题讨论】:

    标签: github google-colaboratory arff


    【解决方案1】:
    1. Python 文件打开只在本地查看。要从 Internet 打开文件,您需要使用请求下载它。
    2. 链接必须是“原始”版本(使用raw.githubusercontent 而不是github.com)并删除其中的"/blob/" 部分。

    这个问题应该对你有帮助:How to download and write a file from Github using Requests

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 1970-01-01
      • 2013-07-26
      • 2018-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      相关资源
      最近更新 更多