title: Joining Multiple Lines in Python (Text Formatting)
body: <p>I am working on pulling logs through an web API and so far when pulling the logs they return in the following format  (3 events below starting with  and ending with .  My question is what would be the best way to loop through each line and concatenate them so that the result event looks like below.</p>
  
  <p>Current output</p>
  
  <pre><code>&lt;attack_headlines version="1.0.1"&gt;
    &lt;attack_headline&gt;
      &lt;site_id&gt;1&lt;/site_id&gt;
      &lt;category&gt;V2luZG93cyBEaXJlY3RvcmllcyBhbmQgRmlsZXM=&lt;/category&gt;
      &lt;subcategory&gt;SUlTIEhlbHA=&lt;/subcategory&gt;
      &lt;client_ip&gt;172.17.1.126&lt;/client_ip&gt;
      &lt;date&gt;1363735940&lt;/date&gt;
      &lt;gmt_diff&gt;0&lt;/gmt_diff&gt;
      &lt;reference_id&gt;6D13-DE3D-9539-8980&lt;/reference_id&gt;
    &lt;/attack_headline&gt;
  &lt;/attack_headlines&gt;
  &lt;attack_headlines version="1.0.1"&gt;
    &lt;attack_headline&gt;
      &lt;site_id&gt;1&lt;/site_id&gt;
      &lt;category&gt;V2luZG93cyBEaXJlY3RvcmllcyBhbmQgRmlsZXM=&lt;/category&gt;
      &lt;subcategory&gt;SUlTIEhlbHA=&lt;/subcategory&gt;
      &lt;client_ip&gt;172.17.1.136&lt;/client_ip&gt;
      &lt;date&gt;1363735971&lt;/date&gt;
      &lt;gmt_diff&gt;0&lt;/gmt_diff&gt;
      &lt;reference_id&gt;6D13-DE3D-9539-8981&lt;/reference_id&gt;
    &lt;/attack_headline&gt;
  &lt;/attack_headlines&gt;
  &lt;attack_headlines version="1.0.1"&gt;
    &lt;attack_headline&gt;
      &lt;site_id&gt;1&lt;/site_id&gt;
      &lt;category&gt;V2luZG93cyBEaXJlY3RvcmllcyBhbmQgRmlsZXM=&lt;/category&gt;
      &lt;subcategory&gt;SUlTIEhlbHA=&lt;/subcategory&gt;
      &lt;client_ip&gt;172.17.1.156&lt;/client_ip&gt;
      &lt;date&gt;1363735975&lt;/date&gt;
      &lt;gmt_diff&gt;0&lt;/gmt_diff&gt;
      &lt;reference_id&gt;6D13-DE3D-9539-8982&lt;/reference_id&gt;
    &lt;/attack_headline&gt;
  &lt;/attack_headlines&gt;
  </code></pre>
  
  <p>Expected output</p>
  
  <pre><code>&lt;attack_headlines version="1.0.1"&gt;&lt;attack_headline&gt;&lt;site_id&gt;1&lt;/site_id&lt;category&gt;V2luZG93cyBEaXJlY3RvcmllcyBhbmQgRmlsZXM=&lt;/category&lt;subcategory&gt;SUlTIEhlbHA=&lt;/subcategory&gt;&lt;client_ip&gt;172.17.1.156&lt;/client_ip&lt;date&gt;1363735975&lt;/date&gt;&lt;gmt_diff&gt;0&lt;/gmt_diff&lt;reference_id&gt;6D13-DE3D-9539-8982&lt;/reference_id&gt;&lt;/attack_headline&lt;/attack_headlines&gt;
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <pre><code>import json
  import os
  from suds.transport.https import WindowsHttpAuthenticated
  
  class Helpers:
          def set_connection(self,conf):
                          #SUDS BUG FIXER(doctor)
                          protocol=conf['protocol']
                          hostname=conf['hostname']
                          port=conf['port']
                          path=conf['path']
                          file=conf['file']
                          u_name=conf['login']
                          passwrd=conf['password']
                          auth_type = conf['authType']
  
                          from suds.xsd.doctor import ImportDoctor, Import
                          from suds.client import Client
  
                          url = '{0}://{1}:{2}/{3}/{4}?wsdl'.format(protocol,
                          hostname,port, path, file)
  
                          imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
                          d = ImportDoctor(imp)
                          if(auth_type == 'ntlm'):
                                  ntlm = WindowsHttpAuthenticated(username=u_name, password=passwrd)
                                  client = Client(url, transport=ntlm, doctor=d)
                          else:
                                  client = Client(url, username=u_name, password=passwrd, doctor=d)
                          return client
          def read_from_file(self, filename):
                  try:
                          fo = open(filename, "r")
                          try:
                                  result = fo.read()
                          finally:
                                  fo.close()
                                  return result
                  except IOError:
                          print "##Error opening/reading file {0}".format(filename)
                          exit(-1)
  
  
          def read_json(self,filename):
                  string=self.read_from_file(filename)
                  return json.loads(string)
  
  
          def get_recent_attacks(self, client):
              import time
              import base64
              from xml.dom.minidom import parseString
              epoch_time_now = int(time.time())
              epochtimeread = open('epoch_last', 'r')
              epoch_time_last_read = epochtimeread.read()
              epochtimeread.close()
              epoch_time_last = int(float(epoch_time_last_read))
              print client.service.get_recent_attacks("",epoch_time_last,epoch_time_now,1,"",15)
  </code></pre>