将API数据导出到.csv。在excel中发出行长度不均匀

时间:2015-11-19 15:17:30

标签: python excel api

我已成功将我需要的数据从API导出到.csv文件。但是,由于许多原因,excel中的行号不一致。我想我需要某种分裂,但我不太确定如何使行成为统一的数字。

with open(sys.argv[1], 'wb') as out_file:
     print >> out_file, 'task_id, num_hearts, task_notes,task_type/task_author, task_completed, task_text, task_modified\n'
     csv = writer(out_file)
     task_count = 0

for task in tasks:
    print task["id"]
    print task["notes"]
    print task["num_hearts"]
    print task["name"]
    print task['completed_at']
    print task['completed']
    print task['due_on']
    print task['due_at']
    print task['workspace']

    foop = task['notes'].replace('\n', ' ').replace('\r', '')

    # Pull out various data from the tasks
    row = (
        task['id'],
        task['num_hearts'],                    
        foop,            
        task['name'],   
        task['completed_at'],                                             
        task['completed'],
        task['due_on'],
        task['due_at'],
        #task['parent'], 
        task['workspace'],

    )




    values = [(value.encode('utf8') if hasattr(value, 'encode') else value) for value in row]
    csv.writerow(values)

0 个答案:

没有答案