Property getter/setter have no effect in Python 2

后端 未结 1 1086
借酒劲吻你
借酒劲吻你 2020-12-03 21:49

I\'m a bit confused about properties in python. Consider the following code

class A:
    @property
    def N(self):
        print(\"A getter\")
        retur         


        
相关标签:
1条回答
  • 2020-12-03 22:34

    A and B must be new-style classes in Python 2.x.

    property([fget[, fset[, fdel[, doc]]]])

    Return a property attribute for new-style classes (classes that derive from object).

    So if you'll derive from object

    class A(object):
       ...
    
    class B(object):
        ...
    

    Your code will work as expected.

    0 讨论(0)
提交回复
热议问题