Self function

Lie Ryan lie.1296 at
Wed May 6 13:49:15 CEST 2009

Luis Zarrabeitia wrote:
> Btw, is there any way to inject a name into a function's namespace? Following 
> the python tradition, maybe we should try to create a more general solution!

How about a mechanism to pass arguments that are optional to accept?

So (in the general case) the caller can call a function with certain 
arguments, but unless the function explicitly accept it, the argument 
will be discarded.

With this, the injecting a local would simply be a case of adding an "I 
accept the argument" statement.

Sort of like this:

def func():
     ''' I reject '''

func(@somearg='Feel free to accept this arg')

def func(@somearg):
     ''' I accept '''

func(@somearg='Feel free to accept this arg')

Then on the case of injecting locals is simply by wrapping the function 
with a function that will inject various argument to the function and 
the function selectively choose which arguments they want to accept.

def needinfo(f):
     # let's assume there is an inspect code here

def func(@__name__, @__call__):
     print 'Hi, my name is %s and to call me press %s' % (__name__, 

Does it sounds like a feature smell?

More information about the Python-list mailing list