我正在解析这个python脚本生成的文件:
import sys
import random
letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
try:
filename, n_tuples = sys.argv[1:3]
n = int(n_tuples)
except:
print 'Usage: %s <outfile> <number of tuples>' % sys.argv[0]
sys.exit(0)
with open(filename, 'w') as f:
for _ in xrange(n):
row = []
for a in range(100):
row.append(''.join([random.choice(letters) for j in range(10)]))
print >>f, ",".join(row)
print "Generated %d random tuples in %s." % (n, filename)
如下所示:
python <script> <outfile> <number of tuples>
它生成1000行100个以逗号分隔的十个字符组,这些字符以下列格式显示在各种编辑器中:
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n
...
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx <--final line: no terminating newline
但是,输出的大小(ls -l outfile = 1100000)和我的解析器同意文件末尾有换行符。
如果此文件末尾有换行符,为什么不能显示&#34;&#34;在编辑?
编辑回应abamert的评论:
以下是给定电话的输出:
>> python <script> <outfile> 1000
Generated 1000 random tuples in <outfile>.
这是前22个字符:
>> head -c 22 csv_file2
HLNLTACOFP,YLWASEJXIN,