IndentationError: unindent does not match any outer indentation level - tokenize, line 8
<pre><code>import calendar

def leapyr(year1, year2):
    count = 0
    while year1 &lt;= year2:
        if calendar.isleap(year1) == True:
            count = count + 1
        year1 = year1 + 1 
    print count

leapyr(2008, 1015)
</code></pre>

<p>i have no bloody idea why this doesnt work. I tried "python -m tabnanny thefile.py" it tells me "indentation error: ((tokenize), line 8)" but i have no idea what to make of that information. </p>

<p>Python allows mixing tabs and spaces. Before interpreting the source, python interpreter replaces tabs with spaces in such way that each tab is aligned to 8 spaces (see <a href="https://docs.python.org/2/reference/lexical_analysis.html#indentation" rel="nofollow">the doc on indentation</a>).</p>

<p>If your editor is set to show tabs as 8 spaces, that should actually work as expected, but if it shows tabs as 4 spaces, then what it looks like is nothing like what the interpreter sees.</p>

<p>The code from the question is:</p>

<hr>

<p><code>import calendar</code></p>

<p><code>def leapyr(year1, year2):</code></p>

<p><kbd>4 spaces</kbd><code>count = 0</code></p>

<p><kbd>4 spaces</kbd><code>while year1 &lt;= year2:</code></p>

<p><kbd>tab</kbd><kbd>4 spaces</kbd><code>if calendar.isleap(year1) == True:</code></p>

<p><kbd>tab</kbd><kbd>tab</kbd><kbd>4 spaces</kbd><code>count = count + 1</code></p>

<p><kbd>tab</kbd><kbd>tab</kbd><code>year1 = year1 + 1</code></p>

<p><kbd>tab</kbd><code>print count</code></p>

<p><kbd>tab</kbd></p>

<p><code>leapyr(2008, 1015)</code></p>

<hr>

<p>That is interpreted by Python as:</p>

<pre><code>import calendar

def leapyr(year1, year2):
    count = 0
    while year1 &lt;= year2:
            if calendar.isleap(year1) == True:
                    count = count + 1
                year1 = year1 + 1 
        print count

leapyr(2008, 1015)
</code></pre>

<p>This has an indentation error in line 8, at <code>year1 = year1 + 1</code>.</p>

<p>The solution is to configure the editor to always use spaces, i.e. to replace tabs with 4 spaces.</p>

python