Parsing specific contents in a file
<p>I have a file that looks like this</p>

<pre><code>    !--------------------------------------------------------------------------DISK
    [DISK]
    DIRECTION  =  'OK'
    TYPE       =  'normal'

    !------------------------------------------------------------------------CAPACITY
    [CAPACITY]
    code            =    0
    ID          =   110
</code></pre>

<p>I want to read sections [DISK] and [CAPACITY].. there will be more sections like these. I want to read the parameters defined under those sections.</p>

<p>I wrote a following code: </p>

<pre><code>file_open = open(myFile,"r")
all_lines = file_open.readlines()
count = len(all_lines)
file_open.close()
my_data = {}
section = None
data = ""
for line in all_lines:
  line = line.strip()                               #remove whitespace
  line = line.replace(" ", "")      
  if len(line) != 0:               # remove white spaces between data        
      if line[0] == "[":
          section = line.strip()[1:]
          data = ""
      if line[0] !="[":
          data += line + "," 
          my_data[section] = [bit for bit in data.split(",") if bit != ""]
print my_data
key = my_data.keys()
print key   
</code></pre>

<p>Unfortunately I am unable to get those sections and the data under that. Any ideas on this would be helpful.</p>
