Using property() on classmethods

后端 未结 15 917
Happy的楠姐
Happy的楠姐 2020-11-22 16:55

I have a class with two class methods (using the classmethod() function) for getting and setting what is essentially a static variable. I tried to use the property() functi

15条回答
  •  被撕碎了的回忆
    2020-11-22 17:34

    Python 3.9 2020 UPDATE

    You can just use them together (taken from the 3.9 docs):

    class G:
        @classmethod
        @property
        def __doc__(cls):
            return f'A doc for {cls.__name__!r}'
    
    

    See https://docs.python.org/3/howto/descriptor.html#id27

提交回复
热议问题