Need help with Python scoping rules

kj at
Wed Aug 26 22:16:54 CEST 2009

In <7figv3F2m3p0dU1 at> "Diez B. Roggisch" <deets at> writes:

>But if you insist on the above methodology, you can do this:

>class Demo(object):

>    def fact(n):
>        def inner(n):
>            if n < 2:
>                return 1
>            else:
>                return n * inner(n - 1)
>        return inner(n)

>    _classvar = fact(5)

>This makes inner a *local* variable, which is found.

Thanks for this.  I think this is the most straightforward workaround.


More information about the Python-list mailing list