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.

2
  • Try looking at Is there a way to import csv file from github automatically to my jupyter notebook. Commented Oct 11, 2022 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) Commented Oct 12, 2022 at 17:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.