Python not defined error when using with block
<pre><code>class fcount(object):
    def __init__(self, func):
            self.func = func
            self.count = 0
            self.context_count = 0
    def __enter__(self):
            self.context_count = 0
    def __call__(self, *args):
            self.count += 1
            self.context_count += 1
            return self.func(*args)
    def __exit__(self, exctype, value, tb):
            return False
</code></pre>

<p>This is a decorator. The idea is to keep a separate count when using a 'with' block.</p>

<p>If I do this:</p>

<pre><code>@fcount
def f(n):
    return n+2

with fcount(foo) as g:
    print g(1)
</code></pre>

<p>I get this error:
TypeError: 'NoneType' object is not callable</p>

<p>I tried printing out the type of g inside that with block, and of course the type is None.</p>

<p>Any idea why g isn't being assigned to fcount(foo)?</p>

<p>This does work:</p>

<pre><code>g = fcount(foo)
with g:
    g(1)
</code></pre>
