[python] pass the name of args

Terry Reedy tjreedy at udel.edu
Fri Jun 4 13:49:51 EDT 2010


On 6/4/2010 7:32 AM, macm wrote:

A few types of objects have definition names (.__name__ attribute). All 
have 0 to many namespace names. If you want to pass an attribute name, 
pass it -- as a string.

> def myDef(x)
> 	doSomething x
> 	result = x.????
> 	return coolThings

def f(x. x_attr_name):
   ...
   res = getattr(x, x__attr_name)
   ...

Terry Jan Reedy




More information about the Python-list mailing list