I'm having an issue parsing a text file into a dictionary
<p>I have a text file, and I want to load it into a dictionary in Python.  </p>

<p>text looks like this, tab delimiated:</p>

<blockquote>
  <p>Form   Dosage  ReferenceDrug   drugname    activeingred
  INJECTABLE; INJECTION  20,000 UNITS/ML     LIQUAEMIN SODIUM    HEPARIN SODIUM
  INJECTABLE; INJECTION  40,000 UNITS/ML     LIQUAEMIN SODIUM    HEPARIN SODIUM
  INJECTABLE; INJECTION  5,000 UNITS/ML      LIQUAEMIN SODIUM    HEPARIN SODIUM</p>
</blockquote>

<p>And right now my code looks like this, but it does not work (list index out of range, and nothing pushed to the dictionary).  I dont know where I'm going wrong, not a programmer.  Thanks for any help. </p>

<pre><code>import sys

def load_medications(filename):
    meds_dict = {}
    f = open(filename)
    l = " "
    # print f.read()
    for line in f:
        fields = l.split("\t")
        ApplNo = fields[0]
        ProductNo = fields[1]
        Form = fields[2]
        Dosage = fields[3]
        ProductMktStatus = fields[4]
        TECode = fields[5]
        ReferenceDrug = fields[6]
            DrugName = fields[7]
        ActiveIngred = fields[8]

        meds = {
                "ApplNo": ApplNo,   
                "ProductNo": ProductNo, 
                "Form": Form,
                "Dosage": Dosage,   
                "ProductMktStatus": ProductMktStatus,
                "TECode": TECode,
                "ReferenceDrug": ReferenceDrug, 
                "DrugName": DrugName,
                "ActiveIngred": ActiveIngred
            }       
        meds_dict[DrugName] = meds
    f.close()
    return meds_dict


def main():
    x = load_medications("druglist.txt")
    print x



if __name__ == "__main__":
    main()
</code></pre>
