Note that there are some explanatory texts on larger screens.

plurals
  1. POWritelines writes lines without newline, Just fills the file..
    primarykey
    data
    text
    <p>I have a program that writes a list to a file. The list is a list of pipe delimited lines and the lines should be written to the file like this:</p> <pre><code>123|GSV|Weather_Mean|hello|joe|43.45 122|GEV|temp_Mean|hello|joe|23.45 124|GSI|Weather_Mean|hello|Mike|47.45 </code></pre> <p>BUT it wrote them line this ahhhh:</p> <pre><code>123|GSV|Weather_Mean|hello|joe|43.45122|GEV|temp_Mean|hello|joe|23.45124|GSI|Weather_Mean|hello|Mike|47.45 </code></pre> <p>This program wrote all the lines into like one line without any line breaks.. This hurts me a lot and I gotta figure-out how to reverse this but anyway, where is my program wrong here? I thought write lines should write lines down the file rather than just write everything to one line..</p> <pre><code>fr = open(sys.argv[1], 'r') # source file fw = open(sys.argv[2]+"/masked_"+sys.argv[1], 'w') # Target Directory Location for line in fr: line = line.strip() if line == "": continue columns = line.strip().split('|') if columns[0].find("@") &gt; 1: looking_for = columns[0] # this is what we need to search else: looking_for = "Dummy@dummy.com" if looking_for in d: # by default, iterating over a dictionary will return keys new_line = d[looking_for]+'|'+'|'.join(columns[1:]) line_list.append(new_line) else: new_idx = str(len(d)+1) d[looking_for] = new_idx kv = open(sys.argv[3], 'a') kv.write(looking_for+" "+new_idx+'\n') kv.close() new_line = d[looking_for]+'|'+'|'.join(columns[1:]) line_list.append(new_line) fw.writelines(line_list) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload