0

I just want to read a CSV file from a Github repo with PyGithub.

from github import Github
g = Github(token)

repo = g.get_repo("user/example")
contents = repo.get_contents("h.csv")

with open(contents, "r") as f1:
    last_line = f1.readlines()[-1]
last_id_csv = last_line.split(",")[0]

But I don't know how to manage ContentFile() type to have the CSV file.

CSV file content is something like:

id,number,text
1,1234,blabla
2,2345,blabla
3,4534,blabla
4,3423,blabla

Thanks for your help.

carlosnev
  • 1
  • 1
  • Try looking at [Is there a way to import csv file from github automatically to my jupyter notebook](https://stackoverflow.com/questions/60609760/is-there-a-way-to-import-csv-file-from-github-automatically-to-my-jupyter-notebo). – Alias Cartellano Oct 11 '22 at 16:04
  • I have decoded the content, but it is still not recognised as CSV. If I try a csv.reader, it doesn't print the entire row. Code until now: `from github import Github g = Github(token) repo = g.get_repo("user/example") contents = repo.get_contents("h.csv") inputFile = contents.decoded_content.decode('utf-8') tocsv = csv.reader(inputFile, delimiter=',') for row in tocsv: print(row)` – carlosnev Oct 12 '22 at 17:14

0 Answers0