title: Python: Splitting a string by delimiter and writing to columns in excel file
body: <p>I have a text file with the following hex string:-</p>
  
  <pre><code>ffffe7ba2cffffe7c52cffffe7c22cffffe7c12cffffe7c82cffffe7c62cffffe7b52cffffe7a02c
  </code></pre>
  
  <p>I want to split this string by the delimiter 2c (which appears in the string after every 8 characters).</p>
  
  <p>Then I want to store the sub-strings in a column in an excel file, so the excel file would look like:-</p>
  
  <p><a href="https://i.stack.imgur.com/64X2E.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/64X2E.jpg" alt="Excel"></a></p>
  
  <p>So far I am able to open the text file, read the data, split it by the delimiter 2c, and write it <strong>vertically</strong> to the excel file using the following (shabby) code:-</p>
  
  <pre><code>    with open(inputfilename, 'r') as myfile:
          string1 = myfile.readline()
  
      string2 = ((str((string1).split("2c"))).replace("'", ""))
  
      with open(outputfilename, "a+") as myfile1:
          myfile1.write(string2)
  </code></pre>
  
  <p>Please suggest how can I split the string and write the sub-strings to a column in excel file efficiently.</p>
  
  <p><strong><em>Thanks in advance!</em></strong></p>
  
  <p>Edit 1:</p>
  
  <p><strong>Almost</strong> got it with:-</p>
  
  <pre><code>with open(inputfilename, 'r') as text_file, open(outputfilename, 'a') as myfile:  
      for line in text_file:
          string1 = str(line.split("2c"))
          string2 = string1.replace("'", "")
          myfile.write("%s" %string2)
          myfile.write("\n")
  </code></pre>
  
  <p>except that the "\n" doesn't write the value to a newline in the excel file.</p>
  
  <p>I have even opened the excel file with "a" access mode, however still writing the values vertically. Any suggestions?</p>