introspection?

J

Jim Benson

newbie question here:

How does one get the class and method name from within
a method? i.e here i have obviously hardcoded the class
and method name:

class JJTest:

def methodA(self):

print 'ERROR: in JJTest.methodA'

The Java way of doing this would be something like:

System.out.println("ERROR in: " + this.getClass().getName());

I suspect that there are attributes that one can use to do
something similar in Python.

If any of you Python experts would let me know how to do this in
Python, i would appreciate it.

Thanks,

Jim
 
N

Neal Norwitz

Jim Benson said:
How does one get the class and method name from within
a method?
... def foo(self):
... print self.__class__.__name__, sys._getframe().f_code.co_name
... C foo

Neal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top