Reputation: 55
So when I use csv writer to print out a list of arguments it prints blank line between rows.So something like this:
My question is what am I doing wrong that makes csv writer produce the blank lines. Here is my code:
row_count = 0
with open(config['LeadImportFilePath']['LeadImportFilePath'] + lead_import_name, 'w') as f:
writer = csv.writer(f)
writer.writerow(config['Headers']['LeadImportHeaders'].split(','))
while row_count <= record_rows:
person_row = [GetCampaignInformation.publisher_id, GetCampaignInformation.source_id, GetPersonInformation.first_name[row_count],
GetPersonInformation.last_name[row_count], GetPersonInformation.GetEmail(), GetPersonInformation.phone[row_count],
GetCampaignInformation.GetIndustry(), GetCampaignInformation.GetJobTitles(), GetPersonInformation.company_name[row_count],
GetPersonInformation.address_1[row_count], GetPersonInformation.address_2[row_count], GetPersonInformation.city[row_count],
GetPersonInformation.state[row_count], GetPersonInformation.zip[row_count], GetCampaignInformation.country, GetCampaignInformation.GetCompanySize(),
lead_create_date, GetCampaignInformation.ReturnAsset(), campaign_id] + GetCampaignInformation.GetCustomQuestion()
writer.writerow(person_row)
row_count += 1
I also get this error: person_row = [GetCampaignInformation.publisher_id, GetCampaignInformation.source_id, GetPersonInformation.first_name[row_count], IndexError: list index out of range
Upvotes: 0
Views: 580
Reputation: 55
Adding wb instead of w on the with open line like the documentation said to do fixed this problem. Who knew that python documentation was correct.
with open(config['LeadImportFilePath']['LeadImportFilePath'] + lead_import_name, 'wb') as f:
Here is the documentation for this problem. Read csv.writer section
Upvotes: 1
Reputation: 61
Maybe you have in CustomQuestion "\n" in the end. Remove last char in CustomQuestiom and try again
Upvotes: 0