Hi,
I have written a the following python code to analyse a function or a method. I am having a script which is having a python function (add) and a class (MyClass) with a method (multiply).When I analyse it using the following method(analyze_func) , I get an output like below.
The problem I am having is, I need to get the value 'MyClass.multiply' from the obj. When I do obj.__name__ , I am only getting "multiply" only.So can anyone propose me how to get the value 'MyClass.multiply'.
-----------------------------------------------
# OUTPUT
-----------------------------------------------
object passed to func() is <unbound method MyClass.multiply>
Method: multiply
===testing code===
result is multiply
===testing code===
Method Arguments: var1 var2
object passed to func() is <function add at 0xb65aa7d4>
Function: add
===testing code===
result is add
===testing code===
Method Arguments: var1 var2
------------------------------------------------
# PYTHON SCRIPT
-----------------------------------------------
def analyze_func(obj, method=False):
str1 = ''
global result
print '%s' % obj.__name__
print 'object passed to func() is ' , obj
if method:
print 'Method: %s' % obj.__name__
strme = '%s' % obj.__name__
str1=strme
else:
print 'Function: %s' % obj.__name__
strme = '%s' % obj.__name__
str1=strme