I have the following code which writes a data output to a csv file. I want to add a date variable at the end of each row using the yesterday.strftime variable that i am using in creating the filename. For example:
Thanks!
my current output is like:
columnA
1
2
and I want to add the following column:
Date
2/5/2016
2/5/2016
. . .
CODE::
filepath = 'C:\\test\\'
filename = yesterday.strftime('%Y-%m-%d') + '_' + 'test.csv'
f = open( filename, 'wt')
writer = csv.writer(f, lineterminator='\n')
header = [h['name'][3:] for h in results.get('columnHeaders')]
writer.writerow(header)
print(''.join('%30s' % h for h in header))
# Write data table.
if results.get('rows', []):
for row in results.get('rows'):
writer.writerow(row)
print(''.join('%30s' % r for r in row))
else:
print ('No Rows Found')
f.close()
resultscome from? You might have to look thereif results.get('rows', []):,for row in results.get('rows'):with justif results.get('rows'):,for row in results['rows']:; the first usage doesn't use the default for anything but a boolean test (so the default default ofNoneis fine), and the second already knows the key exists, so no need to use.getat all.