ずいぶん前にRubyでクラスメソッドを調べるinspectメソッドをやりましたが
shuzo-kino.hateblo.jp
Pythonにも、そういうのがあります。
実際のところ
組込みモジュールなので、特に導入の必要なし。
import inspect class MyClass: def method_one(self): print("現在のメソッド名:", self.get_current_method_name()) def method_two(self): print("現在のメソッド名:", self.get_current_method_name()) def get_current_method_name(self): return inspect.currentframe().f_back.f_code.co_name # クラスのインスタンスを作成してメソッドを呼び出す my_instance = MyClass() my_instance.method_one() my_instance.method_two()
デバッグログ用に使う分には有用そうです。