I am stuck on a problem where my script writes to multiple columns and not rows. I’m not sure what I am doing wrong.
Disclosure – I am really new to programming.
EDIT – Figured it out. This worked 🙂
Any thoughts?
import json
import csv
import subprocess
import urllib
import requests
from unidecode import unidecode
def main():
list_writer= open_csv()
info = test_method()
for list in info:
write_to_csv(list_writer, list)
def test_method():
r = requests.get('https://api.github.com/legacy/repos/search/python'+'?start_page=1', auth=('user', 'pass'))
dict_of_repos = json.loads(r.text)
list_of_repos = dict_of_repos["repositories"]
repo_information = []
for repo in list_of_repos:
indiv_repo = []
indiv_repo.append(repo["name"])
indiv_repo.append(repo["fork"])
print indiv_repo
repo_information.append(indiv_repo)
return repo_information
def open_csv():
github_csv = open('Githubcsv_1_2.csv', 'wb')
writer = csv.writer(github_csv)
return writer
def write_to_csv(list_writer, info):
list_writer.writerow(info)
return
if __name__ == '__main__':
main()
it looks like your
repo_informationwill look likeso it looks like all you need is to
writerowsThis, of course, will write all the data to one column (each name being on a seperate row). If you want to write it all to the same row you could:
and then
writerowlike you are currently doing. This would then put all the names in the same row.