how to get name of function from within function?

Steven Bethard steven.bethard at
Sat Jun 4 23:30:48 CEST 2005

Christopher J. Bottaro wrote:
> Kent Johnson wrote:
>>class C(object):
>>    @in_try
>>    def func_a(self):
>>        print "func_a"
>>    @in_try
>>    def func_b(self):
>>        print "func_b"
>>        raise Exception
>>You could probably create a metaclass to apply the wrappers automatically
>>but I like having it explicit as above.
> Another good solution, thank you.  Maybe a reason to upgrade to 2.4...=)

If you can't upgrade, you can write Kent's code like:

class C(object):
    def func_a(self):
        print "func_a"
    func_a = in_try(func_a)

    def func_b(self):
        print "func_b"
        raise Exception
    func_b = in_try(func_b)


More information about the Python-list mailing list