Python 编辑器看不到最终换行符

Python 编辑器看不到最终换行符,python,append,editor,newline,Python,Append,Editor,Newline,我正在分析此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(

我正在分析此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)

emacs
在文件末尾向我显示一个换行符。
vi
没有在文件末尾显示换行符。这不是一个完整的程序,您的输入显然只是要打印一条
用法
消息。如果你想让我们调试你的代码,你必须给我们一个调试的机会。(如果你只是以一种显而易见的方式修补这些问题,那么它就不会有你最初描述的问题,因此你的实际示例可能不同于以一种显而易见的方式修补这些问题。)@abamert:这就是确切的脚本。完整调用是
python
,以防您想知道它正在解析的参数数量。Yoel已经毫无问题地运行了我发布的内容。我想我遗漏了导入语句。我现在将添加这些。
python <script> <outfile> <number of tuples>
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n
...
xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx <--final line: no terminating newline
>> python <script> <outfile> 1000
Generated 1000 random tuples in <outfile>.
>> head -c 22 csv_file2
HLNLTACOFP,YLWASEJXIN,