【发布时间】:2012-08-01 08:38:34
【问题描述】:
我正在尝试将一个 numpy 数组写入 txt 文件:
a = numpy.array([1,2,3])
numpy.savetxt('a.txt',a,fmt='%.3f')
当我打开 txt 文件时,它看起来像:
1.0002.0003.000
但是当我将它粘贴到 word 中时,它看起来像:
1.000
2.000
3.000
问题是另一个程序逐行读取txt文件作为输入:
data = fid.readlines()
因此无法正常工作。我该如何解决这个问题?
【问题讨论】:
-
你使用的是什么操作系统?
-
我不能 100% 确定细节,但我知道 windows、mac os 和 linux 使用不同的字符作为换行符。
\n(回车)用于 unix/linux,\r(换行)用于 mac 操作系统,\n\r用于 Windows。在 python 中打开文件并执行print(repr(fid.read()))看看它是否包含什么类型的换行符。