Reputation: 1591
I am currently printing data from a rest api. It is able to print fine, but I want to save the output to a column on a csv. I get the error
TypeError: writerows() argument must be iterable
Here is my code:
with open('mycsvfile.csv', 'wb') as f:
for issue in jira.search_issues('project in (FITQA, UXSCIENCE, '
'FITSW, FIT) AND status = Resolved AND environment ~ "TC*" '
'ORDER BY created DESC', maxResults=100):
a = issue.fields.priority
print a
writer = csv.writer(f)
writer.writerows(a)
Upvotes: 1
Views: 8241
Reputation: 7773
writer.writerows()
expects an iterable, for example a list, which it can convert into a set of rows. Since this conversion requires an iterable, we're talking about something like a list of lists.
writer.writerow()
expects an iterable, which it can convert into a row - that is, a list of values. If you want to just write this value as a single column in a one-column csv, you could do
writer.writerow([a])
But if you want it included with other data, you're going to have to produce that list of values:
data.append(a)
writer.writerow(data)
(data
here is some existing list of values that you've already assembled)
Upvotes: 3