title: What is Wrong with the for Loops
body: <p>I can't get an output from this code, it is just looping infinitely I guess, it has to readlines and append those lines to the list named data, but it doesn't give an output, what have I done wrong?
  Any suggestions will be appreciated, thanks in advance.</p>
  
  <pre><code>import os
  import subprocess
  import commands
  
  command = ['sudo', 'iwlist', 'wlan0', 'scan']
  output = subprocess.Popen(command, stdout=subprocess.PIPE).stdout.readlines()
  data = []
  for item in output:
        if item.strip().startswith('ESSID:'):
             data = (item.lstrip('ESSID:').rstrip('\n'))
        for item in output:
              if item.strip().startswith('Quality:'):
                   data.append('Quality:')
              for item in output:
                    if item.strip().startswith('Pairwise:'):
                         data.append('Pairwise:')
                         print data
  </code></pre>