谦虚 发表于 2017-10-19 21:50:12

关于描述符 搞不懂属性的值

class Cel():
    def __init__(self,value=26):
      self.value=float(value)
      print('value=',self.value)

    def __get__(self,instance,owner):
      print('在gel中')
      return self.value

    def __set__(self,instance,value):
      print('在Set中')
      self.value=float(value)
class Fahrenheit:
    def __get__(self,instance,owner):
      return instance.cel*1.8+32
    def __set__(self,instance,value):
      instance.cel=(float(value)-32)/1.8
   

class T():
    cel=Cel()      
                  
    fah=Fahrenheit()

运行后如果用T.cel访问 显示在gel中
26.0 为什么呢?

不自律的笨鸟 发表于 2021-5-15 07:24:45

看来还有很多东西要学习啊!

不自律的笨鸟 发表于 2021-5-18 21:13:59

看来还有很多东西要学习啊!
页: [1]
查看完整版本: 关于描述符 搞不懂属性的值