西宁网站seo公司,公司注册地址必须是商业用房吗,局域网如何建网站,中国网教育Python Day 21 面向对象 (面向对象的三大特性#xff08;二#xff09;继承#xff0c;多态#xff0c;封装#xff0c;几个装饰器函数) https://mubu.com/doc/1AqL_M0IbW 继承之钻石继承 多态 封装 几个装饰器函数 classmethod 可以通过类使用被装饰的方法staticmethod …Python Day 21 面向对象 (面向对象的三大特性二继承多态封装几个装饰器函数) https://mubu.com/doc/1AqL_M0IbW 继承之钻石继承 多态 封装 几个装饰器函数 classmethod 可以通过类使用被装饰的方法staticmethod 可以使用类.方法调用,而且不需要将self作为参数传进去 class MyFlies:__file_namelog# classmethoddef open_file(cls,filename):print(cls.__file_name)with open(filename,rb) as f:return f.read()staticmethoddef look_file(filename):print(根本不知道__file_name的存在)with open(filename,rb) as f:return f.read()def self_open_file(self,filename):print(self.__file_name)with open(filename, rb) as f:return f.read()new_file MyFlies()
print(new_file.open_file(log))
print(MyFlies.open_file(log))
# print(new_file.look_file(mylog.log))
# print(new_file.open_file(mylog.log))
# print(new_file.self_open_file(mylog.log))
# print(MyFlies.open_file(mylog.log))
# print(MyFlies.look_file(mylog.log)) classmethod staticmethod 转载于:https://www.cnblogs.com/eailoo/p/9100845.html