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
  • 相关阅读:
    文本分类的研究学习
    Python中的TfidfVectorizer参数解析
    Newsgroups数据集介绍
    鸢尾花数据读取的总结
    Knapsack Problems
    3.1.6 Stamps
    3.1.5 Contact
    3.1.4 Shaping Regions
    3.1.3 Humble Numbers
    3.1.2 Score Inflation
  • 原文地址:https://www.cnblogs.com/eailoo/p/9100845.html
Copyright © 2011-2022 走看看