0

I want to read a csv file located in a repo every time I run the python script. I have searched for ways to clone a git and locate and read a specific file but haven't been successful. 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.

I am an absolute beginner and there is a high chance I wont understand what directions are given to me.

A M
  • 70
  • 2
  • 8
  • 1
    You were probably looking at code running in Jupyter. The `!` allows to run shell commands. So they are cloning the repo. – prosoitos Oct 27 '20 at 13:42
  • Maybe you find the answer [here]. I hope this helps [here]: https://stackoverflow.com/questions/14120502/how-to-download-and-write-a-file-from-github-using-requests – TheMB Oct 27 '20 at 13:44
  • Yes the code was running in Jupyter. But I am writing my code in jupyter notebook as well, but it isnt running as expected – A M Oct 27 '20 at 13:45

1 Answers1

0

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)