中英文网站怎么做的,小程序 wordpress api,wordpress微博采集,金华网站建设系统在类中定义函数如果 不加装饰器 则默认 为对象作为绑定方法 如果增加 classmethod 是 以 类 作为绑定方法 增加 classmethod 是 非绑定方法#xff0c;就是不将函数 绑定 ##################### class Foo: def func(self): print(self) classmethod def func…在类中定义函数如果 不加装饰器 则默认 为对象作为绑定方法 如果增加 classmethod 是 以 类 作为绑定方法 增加 classmethod 是 非绑定方法就是不将函数 绑定 ##################### class Foo: def func(self): print(self) classmethod def func2(cls): print(cls) staticmethod def sta(): print(非绑定参数)JGFoo()JG.func()JG.func2()JG.sta() ######################## 绑定方法与 非绑定方法的 应用场景;Mysql 连接 绑定对象方法:默认传值 绑定类方法: 可以从文件中读取 默认值 非绑定方法通过time.clock() 生成ID ############################# import set1import hashlibimport timeclass Mysql: def __init__(self,host,port): self.idself.create_id() self.hosthost self.portport classmethod def from_conf(cls): return cls(set1.Host,set1.Port) staticmethod def create_id(): HAShashlib.md5(str(time.clock()).encode(utf-8)) return HAS.hexdigest() classmethod def dele(cls): print(from,delet) def select(self): print(select)JGMysql(192.168.1.1,3306)JG.select()print(JG.create_id()) ############################################# 转载于:https://www.cnblogs.com/onda/p/7008739.html