zoukankan      html  css  js  c++  java
  • Python Day 21 面向对象 (面向对象的三大特性(二)继承,多态,封装,几个装饰器函数)

    Python Day 21 面向对象 (面向对象的三大特性(二)继承,多态,封装,几个装饰器函数)

    https://mubu.com/doc/1AqL_M0IbW

    继承之钻石继承

    多态

    封装

    几个装饰器函数

    @classmethod  可以通过类使用被装饰的方法
    @staticmethod 可以使用类.方法调用,而且不需要将self作为参数传进去
    class MyFlies:
    
        __file_name="log"
    
        # @classmethod
        def open_file(cls,filename):
            print(cls.__file_name)
            with open(filename,"rb") as f:
                return f.read()
    
        @staticmethod
        def 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
  • 相关阅读:
    ExtJs-学习篇(1)
    js中的Ajax经典示例
    软件工程开发流程
    Maven和Ajax
    搭建SSH框架
    拦截器
    OGNL
    Struts 2配置详解
    Struts 2入门
    HQL连接查询和注解
  • 原文地址:https://www.cnblogs.com/eailoo/p/9100845.html
Copyright © 2011-2022 走看看