openpyxl iterate through cells of column => TypeError: 'generator' object is not subscriptable
<p>i I want to loop over all values op a column, to safe them as the key in a dict. As far as i know, everything is ok, but python disagrees.</p>

<p>So my question is: "what am i doing wrong?"</p>

<pre><code>&gt;&gt;&gt; wb = xl.load_workbook('/home/x/repos/network/input/y.xlsx')
&gt;&gt;&gt; sheet = wb.active
&gt;&gt;&gt; for cell  in sheet.columns[0]:
...     print(cell.value)
... 
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
TypeError: 'generator' object is not subscriptable
</code></pre>

<p>I must be missing something, but after a few hours of trying, I must throw in the towle and call in the cavalecry ;)</p>

<p>thanks in advance for all the help!</p>

<p>===================================================================</p>

<p>@Charlie Clark: thanks for taking the time to answer. The thing is, I need the first column as keys in a dict, afterwards, I need to do</p>

<pre><code>for cell  in sheet.columns[1:]:
</code></pre>

<p>so, while it would resolve my issue, it would come back to me a few lines later, in my code. I will use your suggestion in my code to extract the keys.</p>

<p>The question I mostly have is: </p>

<p>why doesn't it work, I am sure I used this code snippet before and this is also how, when googling, people are suggesting to do it.</p>

<p>==========================================================================</p>

<pre><code>&gt;&gt;&gt; for column in ws.iter_cols(min_col = 2):
...     for cell in column:
...             print(cell.value)
</code></pre>

<p>goes over all columns of the sheet, except the first. Now, I still need to exclude the first 3 rows </p>

<p><code>ws.columns</code> returns a generator of columns because this is much more efficient on large workbooks, as in your case: you only want one column. <a href="https://openpyxl.readthedocs.io/en/default/tutorial.html#accessing-many-cells" rel="nofollow">Version 2.4</a> now provides the option to get columns directly: <code>ws['A']</code> </p>

python excel loops openpyxl