Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Object customization

Skip Montanaroskip@mojam.com (Skip Montanaro)
Sun, 16 Apr 2000 17:06:08 -0500 (CDT)


    Ken> We haven't even seen a satisfactory approach to referring to the    Ken> function, itself, from within the function.  Maybe it's not even    Ken> desirable to be able to do that - that's an interesting question.I hereby propose that within a function the special name __ refer to thefunction.  You could have    def fact(n):        if n <= 1: return 1return __(n-1) * nYou could also refer to function attributes through __ (presuming Barry'sproposed patch gets adopted):    def pub(*args):      if __.access == "private":        do_private_stuff(*args)      else:        do_public_stuff(*args)    ...    if validate_permissions():      pub.access = "private"    else:      pub.access = "public"When in a bound method, __ should refer to the bound method, not the unboundmethod, which is already accessible via the class name.As far as lexical scopes are concerned, this won't change anything.  I thinkit could be implemented by adding a reference to the function called __ inthe local vars of each function.-- Skip Montanaro |http://www.mojam.com/skip@mojam.com |http://www.musi-cal.com/


[8]ページ先頭

©2009-2025 Movatter.jp