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
  • 相关阅读:
    1099. Build A Binary Search Tree (30)
    两个新事物
    time.h
    Nohup命令
    进程锁
    C++中虚析构函数的作用
    c++ 修改stl set中的元素
    STL迭代器辅助函数——advance
    CTreeCtrl 控件使用总结
    关于stl advance函数移动步数超过容器大小(越界)的研究
  • 原文地址:https://www.cnblogs.com/eailoo/p/9100845.html
Copyright © 2011-2022 走看看