title: Python function returns 'TypeError: unicode object is not an iterator'
body: <p>I'm not sure if I am missing an obvious answer, but I used to have a script that would read through a txt log file to find a certain log packet string (if 'logpacket' in line:) and then once found, that line and the next x number of lines below would be passed to a function to gather stats splitting on the '=' sign to get Key and Value items which would then be dropped into a dict.</p>
  
  <p>However I have now discovered I no longer need to convert the log into txt (which was time consuming anyway) and I can now search the log directly using my log analysis tool for the same packet.</p>
  
  <p>The packet I am trying to extract info from is in the format below - (it's a GPS packet)</p>
  
  <pre><code>2015 Jan 01  20:07:16.047 GPS Info
  
  GPS Time = 14:18:43.000 
  
  Longitude = 000.65341
  
  Latitude = +41.25385
  
  Altitude = +111.400
  </code></pre>
  
  <p>The following code is where I used to scan the text file and then pass the file object to the function</p>
  
  <pre><code>if 'GPS Info' in line:
      data = process_data(f, 8) #f = file object, 8 = number of lines to process
      packets[data['GPS Time']] = data
  </code></pre>
  
  <p>Here's my function that would dissect the successive lines and split into Key and Value elements for dict creation...</p>
  
  <pre><code>def process_data(file_object, n):
      processed_data = (next(file_object).split('=', 1) for _ in xrange(n))
      return {k.strip(): v.strip() for k, v in processed_data}
  </code></pre>
  
  <p>This method worked excellently for a txt file, but now I am scanning the log file from within the log analysis tool and passing the 'packet' to the function, in other words the whole packet is sent to the function rather than line by line (The packet arrives at the function correctly as I have managed to print the whole packet from within the function).  As the whole packet arrives at the function this explains why I am getting an "object is not an iterator" error, but I am wondering if there is a simple change I am missing to split each line on '=' in the packet block so that I can continue to create the key:value dict setup?</p>
  
  <p>I think I have explained this really badly, I hope some of it makes sense?</p>
  
  <p>Thanks,
  MikG</p>