在 CSV 文件中导出 table
Export a table in CSV file
我通过以下方式生成了一个 table 的 2 次方及其以 2 为底的对数:
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
如何将此 table 导出到 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
我通过以下方式生成了一个 table 的 2 次方及其以 2 为底的对数:
import math
x = 2.0
while x < 100.0:
print x, '\t', math.log(x)/math.log(2)
x = x + x
如何将此 table 导出到 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