K
Koen Van Herck
For debugging/logging purposes, I have a function
def Log(msg):
print '%s.%s: %s' % (cls, method, msg)
I call this function from a class method, and I would like to retrieve
the name of the caller method and its class. I already came up with
method = sys._getframe(1).f_code.co_name
cls = sys._getframe(1).f_locals['self'].__class__
I wonder if there are better ways to retrieve this info. In
particular, my implementation assumes that the instance parameter of
the method is called 'self', which it usually is, of course.
Regards,
Koen.
def Log(msg):
print '%s.%s: %s' % (cls, method, msg)
I call this function from a class method, and I would like to retrieve
the name of the caller method and its class. I already came up with
method = sys._getframe(1).f_code.co_name
cls = sys._getframe(1).f_locals['self'].__class__
I wonder if there are better ways to retrieve this info. In
particular, my implementation assumes that the instance parameter of
the method is called 'self', which it usually is, of course.
Regards,
Koen.