我遇到了一个问题,即我的脚本写入多列而不是行。我不确定我做错了什么。
披露 - 我对编程真的很陌生。
编辑 - 想通了。这有效:-)
有什么想法吗?
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()