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

Ken Manheimer klm@digicool.com
Fri, 14 Apr 2000 15:18:18 -0400 (EDT)


> since when did Python grow full lexical scoping?
> 
> does anyone that has learned about the LGB rule expect
> the above to work?

Not sure what LGB stands for.  "Local / Global / Built-in"?

> 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...

Huh.  ??

I'm assuming your hypothetical foo.x means the attribute 'x' of the
function 'foo' in the global namespace for the function 'foo' - which, 
conveniently, is the module where foo is defined!

8<--- foo.py --->8
def foo():
    # Return the object named 'foo'.
    return foo
8<--- end foo.py --->8

8<--- bar.py --->8
from foo import *

print foo()
8<--- end bar.py --->8

% python bar.py
<function foo at 80eb4c0>
%

I must be misapprehending what you're suggesting - i know you know this
stuff better than i do - but it seems to me that foo.x would work, were
foo to have an x.  (And that foo.x would, in my esteem, be a suboptimal
way to get at x from within foo, but that's besides the fact.)

Ken
klm@digicool.com