A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-April/003558.html below:

Arbitrary attributes on funcs and methods)

[Python-Dev] Object customization (was: Arbitrary attributes on funcs and methods) [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



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4