Python property getter and setter decorator not callable

后端 未结 1 439
花落未央
花落未央 2020-12-11 10:35

I\'m doing something similar to the following

class Parrot(object):
    def __init__(self):
        self.__voltage = 100000

    @property
    def voltage(s         


        
1条回答
  •  温柔的废话
    2020-12-11 11:10

    The whole point of the getter is that it returns the value without being called. p.voltage returns the integer object, so running p.voltage() is equivalent to 100() or something.

    There can still be cases where you want to call the value of a property, like if the value is itself a function. But you don't need it here.

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