how to get name of function from within function?
Steven Bethard
steven.bethard at gmail.com
Mon Jun 6 13:51:07 EDT 2005
Christopher J. Bottaro wrote:
> Steven Bethard wrote:
>>... def _impl_wrapper(self, func):
>>... def wrapper(*args, **kwargs):
>>... try:
>>... return func(*args, **kwargs)
>>... except:
>>... print "entered except"
>>... raise
>>... return wrapper
>>...
[snip]
>
> The problem is:
>
>>>>c.func_b.__name__
>
> 'wrapper'
>
> That messes up SOAPpy's RegisterFunction() method which apparently depends
> on the __name__ of the function to publish it as an available SOAP
> function.
Hmm... Nasty. If you were using Python 2.4, you could simply write it as:
def _impl_wrapper(self, func):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except:
print "entered except"
raise
wrapper.__name__ = func.__name__
return wrapper
Where you fix up the wrapper's __name__ attribute. But I believe the
__name__ attribute is read-only in Python 2.3...
STeVe
More information about the Python-list
mailing list