UnboundLocalError with extra code after return

Chris Rebert clp2 at rebertia.com
Wed Sep 30 00:43:54 EDT 2009


On Tue, Sep 29, 2009 at 9:41 PM, Chris Rebert <clp2 at rebertia.com> wrote:
> On Tue, Sep 29, 2009 at 9:15 PM, Rich Healey <healey.rich at gmail.com> wrote:
>> However:
>>
>> def callonce(func):
>>    def nullmethod(): pass
>>    def __():
>>        return func()
>>        func = nullmethod

Additionally, to rebind a variable in an outer nested function scope
like you tried to do, you'd need a `nonlocal` statement. See
http://www.python.org/dev/peps/pep-3104/

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list