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

Skip Montanaro skip@mojam.com (Skip Montanaro)
Fri, 14 Apr 2000 15:03:41 -0500 (CDT)


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

    Fredrik> fwiw, I'd love to see a good syntax for this.  might even
    Fredrik> change my mind...

Could we overload "_"'s meaning yet again (assuming it doesn't already have
a special meaning within functions)?  That way

    def bar():
       print _.x
    def foo():
       print _.x
    foo.x = "public"
    bar.x = "private"
    bar, foo = foo, bar
    foo()

would display

    private

on stdout.  *Note* - I would not advocate this use be extended to do a more
general lookup of attributes - it should just refer to attributes of the
function of which the executing code object is an attribute.  (It may not
even be possible.)

(I've never used _ for anything, so I don't know all its current (ab)uses.
This is just a thought that occurred to me...)

Skip