【发布时间】:2015-11-29 15:26:11
【问题描述】:
我以 2 的幂及其以 2 为底的对数通过以下方式生成了一个表格:
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
如何将此表导出为 CSV 文件,其中每个元素都与一个单元格完全匹配?
【问题讨论】:
标签: python csv export-to-csv
我以 2 的幂及其以 2 为底的对数通过以下方式生成了一个表格:
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
如何将此表导出为 CSV 文件,其中每个元素都与一个单元格完全匹配?
【问题讨论】:
标签: python csv export-to-csv
见https://docs.python.org/2/library/csv.html#csv.writer
import math
import csv
x = 2.0
with open('out.csv', 'wb') as f:
writer = csv.writer(f, delimiter=',')
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
writer.writerow([x, math.log(x)/math.log(2)])
x = x + x
【讨论】: