Saturday 15 May 2010

python - Final newline character not seen by editors -



python - Final newline character not seen by editors -

i parsing file generated python script:

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) open(filename, 'w') f: _ in xrange(n): row = [] in range(100): row.append(''.join([random.choice(letters) j in range(10)])) print >>f, ",".join(row) print "generated %d random tuples in %s." % (n, filename)

called follows:

python <script> <outfile> <number of tuples>

it generates 1000 lines of 100 comma-separated groups of 10 characters displayed in various editors in next format:

xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx\n ... xxxxxxxxxx,xxxxxxxxxx,...,xxxxxxxxxx <--final line: no terminating newline

however, size of output (ls -l outfile = 1100000) , parser agree there newline @ end of file.

if there newline @ end of file, why might not "displayed" in editors?

edit in response comment abamert:

here output given call:

>> python <script> <outfile> 1000 generated 1000 random tuples in <outfile>.

and here first 22 characters:

>> head -c 22 csv_file2 hlnltacofp,ylwasejxin,

python append editor newline

No comments:

Post a Comment