[英]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.