Need help with Python scoping rules

kj no.email at please.post
Wed Aug 26 22:16:54 CEST 2009


In <7figv3F2m3p0dU1 at mid.uni-berlin.de> "Diez B. Roggisch" <deets at nospam.web.de> 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.

kynn



More information about the Python-list mailing list