A
A
Alexey Yarkov2015-11-12 16:20:35
Python
Alexey Yarkov, 2015-11-12 16:20:35

How to find out the name of the method that called the method?

Hello. Suppose there is a class

class BasePluginClass:


  def Print(self, data):
    # тут нужно узнать имя метода, из которого был вызов
    #run = "Run"
    print data


  def Run(self):
    self.Print("string")

Is there any kosher way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shagguboy, 2015-11-12
@yarkov

https://docs.python.org/2/library/inspect.html#ins...
import inspect
def f1(): f2()
def f2():
print 'caller name:', inspect.stack()[ 1][3]
f1()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question