[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods)

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Fri, 14 Apr 2000 20:29:43 +0200


> To belabor the obvious (existing Python allows obsfuction), I=20
> present:
>=20
> class eff:
>   "eff"
>   def __call__(self):
>     print "eff", eff.__doc__
>    =20
> class bot:
>   "bot"
>   def __call__(self):
>     print "bot", bot.__doc__
>    =20
> e =3D eff()
> b =3D bot()
> e()
> b()
>=20
> eff, bot =3D bot, eff
> e =3D eff()
> b =3D bot()
> e()
> b()=20
>=20
> There's nothing new here. Why does allowing the ability to=20
> obsfucate suddenly warrant a -1?

since when did Python grow full lexical scoping?

does anyone that has learned about the LGB rule expect
the above to work?

in contrast, my example used a name which appears to be
defined in the same scope as the other names introduced
on the same line of source code -- but isn't.

    def foo(x):
        foo.x =3D x

here, "foo" doesn't refer to the same namespace as the
argument "x", but to instead whatever happens to be in
an entirely different namespace at the time the function
is executed.

in other words, this feature cannot really be used to store
statics -- it only looks that way...

</F>