0
0

More than 3 years have passed since last update.

デコレートしている関数の情報を取得する

Last updated at Posted at 2019-12-12

運よく見つけたのでメモ。

test.py
class hogehoge(object):

    def deco(func):
        def inner_deco(self):
            print(func.__name__)
            func(self)
        return inner_deco

    @deco    
    def func1(self):
        pass

    @deco
    def func2(self):
        pass

test = hogehoge()
test.func1()
test.func2()

出力結果

func1
func2

全く調べていないが、たぶんname以外にも様々な種類があり、
その関数の様々な情報をデコレータ側で取得できるのだと思う。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0