Python not printing the correct results, though the results is correct -


i have loaded file list

    line_storage = [];      try:         open(file_name_and_path, 'r') f:             line in f:                 line_storage.append(line)    # store in list 

but when trying convert string ("stringify" it):

 total_number_of_lines = len(line_storage)   linebuffer = "";  line_index in xrange(0, total_number_of_lines):       linebuffer += line_storage[line_index].rstrip('\n') # append line after removing newline 

the print not showing me full content, last line. though, len(linebuffer) correct.

the file contents is: .... [04.01] test 1: you should able read this. [04.02] test 2: .... =========================================================== eof

how can work around this?

your text lines end in \r\n, not \n. removing \n, leaving \r @ end of each line. when print terminal, each line overwrite previous line because \r moves cursor beginning of current line.

the solution use .rstrip('\r\n').


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -