首页 > 代码库 > python基础学习1-描述符

python基础学习1-描述符

#!/usr/bin/env python# -*- coding:utf-8 -*-#描述符就是将某种特殊类型的类的实例指派给另一个类的属性#特殊类型指 实现了# __get__(self,instance,owner),# __set__(self,instance,value),# __delete__(self,instance)三个方法中至少一个class MyDecriptor: #描述符类    def __get__(self, instance, owner):        print("__get__",self, instance, owner)    def __set__(self, instance, value):        print("__set__",self, instance, value)    def __delete__(self, instance):        print("__delete__",self, instance)class Test:    x=MyDecriptor()t1= Test()print(t1.x)t1.x="x-man"#=====》实例温度转换  根据设置的摄氏度换算出华氏度class Celsius:    def __init__(self,value=http://www.mamicode.com/26):>

 

python基础学习1-描述符