Self function

Arnaud Delobelle arnodel at googlemail.com
Tue May 5 09:30:01 EDT 2009


On 5 May, 13:33, Luis Zarrabeitia <ky... at uh.cu> wrote:
> On Tuesday 05 May 2009 02:46:58 am Chris Rebert wrote:
>
> > <devils_advocate>
> > Adding syntax is EVIL(tm) for it angers the Gods of Backwards
> > Compatibility, and this proposal is completely unnecessary because you
> > could instead just write:
> [...]
> > And there would be much clashing with existing variable names,
> > for keywords are the Devil's work!
> > </devils_advocate>
>
> Heh. I liked the proposal (though I'm not 100% sold on the name __this__), and
> one of the reasons I liked it was... it preempted the name-clashing argument.
> Not a new keyword, just a variable that is injected on the local namespace,
> so it would only clash with code that uses __this__ as a global (or that
> expects to use an unbound __this__).

One issue with automatically binding a local variable to the current
function is with nested functions:

def foo()
    def bar():
       # How do I call foo() from here?

One solution would be

def foo()
    def bar(foo=__this__):
        foo()

I don't know, it does not convince me ATM.

--
Arnaud



More information about the Python-list mailing list