Need help with Python scoping rules

Carl Banks pavlovevidence at gmail.com
Wed Aug 26 17:27:24 CEST 2009


On Aug 26, 8:13 am, Dave Angel <da... at ieee.org> wrote:
> You can probably work around this by replacing the staticmethod
> decorator with an equivalent function call:.
>
> class Demo9(object):
>     def fact(n):
>         if n < 2:
>             return 1
>         else:
>             return n * Demo.fact(n - 1)
>
>     _classvar = fact(5)
>     fact = staticmethod(fact)
>
> print Demo9._classvar
> xx = Demo9()
> print xx.fact(6)
> print Demo9.fact(8)

This won't work normally.  It only worked for you because you made a
typo.


Carl Banks



More information about the Python-list mailing list