Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're importing the <a href="http://docs.python.org/library/csv.html" rel="nofollow noreferrer"><code>csv</code> module</a> but never use it. Why?</p> <p>If you do</p> <pre><code>import csv reader = csv.reader(open(file, "rb"), dialect="excel") # Python 2.x # Python 3: reader = csv.reader(open(file, newline=""), dialect="excel") </code></pre> <p>you get a <code>reader</code> object that will contain all you need; the first row will contain the headers, and the subsequent rows will contain the data in the corresponding places. </p> <p>Even better might be (if I understand you correctly):</p> <pre><code>import csv reader = csv.DictReader(open(file, "rb"), dialect="excel") # Python 2.x # Python 3: reader = csv.DictReader(open(file, newline=""), dialect="excel") </code></pre> <p>This <code>DictReader</code> can be iterated over, returning a sequence of <code>dict</code>s that use the column header as keys and the following data as values, so</p> <pre><code>for row in reader: print(row) </code></pre> <p>will output</p> <pre><code>{'Name': 'Nick', 'Designation': 'F4321', 'Type': 'Subject', 'Total': '29', 'First-term assessment': '10', 'Second-term assessment': '19', 'Description': 'D1234'} {'Name': 'HTML', 'Designation': 'F4321', 'Type': 'Unit', 'Total': '', 'First-term assessment': '18', 'Second-term assessment': '', 'Description': 'D1234-1'} {'Name': 'Tags', 'Designation': 'F4321', 'Type': 'Topic', 'Total': '', 'First-term assessment': '18', 'Second-term assessment': '', 'Description': 'First Term'} {'Name': 'Review of representation of HTML', 'Designation': '', 'Type': 'Subtopic', 'Total': '', 'First-term assessment': '', 'Second-term assessment': '', 'Description': ''} </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload