Write String And Integer To Csv File
I have a code whose outputs are mentioned below. print 'Total Bits:%d'%totalbits print 'Number of totalbits-zeros: %d.' %totalbitszeros print 'Number of totalbits-ones: %d.
Solution 1:
You can use the format function. Like this:
data = [['Total Bits', 100]]
with open('output.csv','w') as out:
for row in data:
for col in row:
out.write('{0};'.format(col))
out.write('\n')
Solution 2:
You may try with csv module:
import csv
a = [['Total bits',77826496],['Total number of bits@0',74653999],['Total number of bits@1',3172497],\
['Total number of BRAM bits@0',17242039],['Total number of BRAM bits@1',62089],\
['Total number of non-BRAM bits@0', 57411960],['Total number of non-BRAM bits@',3110408]]
withopen("output.csv", "wb") as f:
writer = csv.writer(f,delimiter=':')
writer.writerows(a)
output.csv
file will be:
Total bits:77826496
Total number of bits@0:74653999
Total number of bits@1:3172497
Total number of BRAM bits@0:17242039
Total number of BRAM bits@1:62089
Total number of non-BRAM bits@0:57411960
Total number of non-BRAM bits@:3110408
Post a Comment for "Write String And Integer To Csv File"