简体   繁体   English

如何从 github 获取文件到我的 python 代码中

[英]How do I get a file from github into my python code

I want to read a csv file located in a repo every time I run the python script.每次运行 python 脚本时,我都想读取位于 repo 中的 csv 文件。 I have searched for ways to clone a git and locate and read a specific file but haven't been successful.我一直在寻找克隆 git 并定位和读取特定文件的方法,但没有成功。 I saw a file where they just wrote: !git clone ~the link of the repo~ in the first line of the code without importing anything.我在代码的第一行看到了一个他们刚刚写的文件: !git clone ~the link of the repo~没有导入任何东西。

I am an absolute beginner and there is a high chance I wont understand what directions are given to me.我是一个绝对的初学者,很有可能我不明白给了我什么方向。

Assuming the repository is public.假设存储库是公开的。

import requests

url = "path/to/raw/file.csv"
resp = requests.get(url)
with open("myfile.csv", "w") as f:
    f.write(resp.text)

暂无
暂无

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

相关问题 如何让 python 从 output 我的代码中写入 csv 文件? - How do I get python to write a csv file from the output my code? 如何获取我的代码以通过python服务器写入文本文件 - How do I get my code to write to the text file over a python server 如何从CSV文件获取值以使用python加载到SQL数据库中? - How do I get to my values from a CSV file to load into my SQL database with python? 如何获取此代码以从单独的文件 python 文件中取出“成本”参数? - How do I get this code to take out the "cost" argument from a separate file python file? 从本地机器上删除文件后,如何从 github 拉取以再次获取该文件? - After deleting a file from my local machine, how do I pull from github to obtain that file again? 我如何获得我的 python 代码以从该站点单击 mp3 下载按钮 - How do i get my python code to click mp3 download button from this site 我如何使用 jupyter 笔记本的 python 代码从网站下载 csv 文件 - how do i download the csv file from a website using python code for my jupyter notebook 如何循环并将我的代码附加到 CSV 文件? - Python - How do I loop and append my code to a CSV file? - Python 如何在我的 Python 代码中添加和打印 txt 文件? - How do i add and print a txt file in my Python code? 如何让我的代码从文本文件中显示一定数量的字符 - How do I get my code to show a certain number of characters from a text file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM