zoukankan      html  css  js  c++  java
  • 20191011作业

    今日作业

    '''
    0、课堂代码理解,并敲两遍以上 (技术的牛逼是靠量的积累)
    
    1、定义MySQL类(参考答案:http://www.cnblogs.com/linhaifeng/articles/7341177.html#_label5)
    	  1.对象有id、host、port三个属性
    	  
    	  2.定义工具create_id,在实例化时为每个对象随机生成id,保证id唯一
    	  
    	  3.提供两种实例化方式,方式一:用户传入host和port 方式二:从配置文件中读取host和port进行实例化
    	  
    	  4.为对象定制方法,save和get_obj_by_id,save能自动将对象序列化到文件中,文件路径为配置文件中DB_PATH,文件名为id号,保存之前验证对象是否已经存在,若存在则抛出异常,;get_obj_by_id方法用来从文件中反序列化出对象
    
    2、定义一个类:圆形,该类有半径,周长,面积等属性,将半径隐藏起来,将周长与面积开放
    		参考答案(http://www.cnblogs.com/linhaifeng/articles/7340801.html#_label4)
    	
    3、使用abc模块定义一个phone抽象类 并编写一个具体的实现类
    
    4、着手编写选课系统作业:http://www.cnblogs.com/linhaifeng/articles/6182264.html#_label15
    
    '''
    
    
    
    '''
    定义一个类:圆形,该类有半径,周长,面积等属性,将半径隐藏起来,将周长与面积开放
    参考答案(http://www.cnblogs.com/linhaifeng/articles/7340801.html#_label4)
    '''
    from math import pi
    class Circle:
        def __init__(self,radius):
            self.__radius = radius
    
        def perimeter(self):
            return (2*pi*self.__radius)
    
        def area(self):
            return (pi*(self.__radius**2))
    c = Circle(5)
    print(c.area())
    print(c.perimeter())
    
    '''
    使用abc模块定义一个phone抽象类 并编写一个具体的实现类
    '''
    import abc
    class Phone:
        def __init__(self,price,screen):
            self.price = price
            self.screen = screen
    
    class Mi(Phone):
        def __init__(self,price,screen):
            super().__init__(price,screen)
            self.brand = 'Mi'
    
        def show(self):
            print(f'{self.brand},{self.price},{self.screen}')
    
    class Iphone(Phone):
        def __init__(self,price,screen):
            super().__init__(price, screen)
            self.brand = 'IPHONE'
    
        def show(self):
            print(f'{self.brand},{self.price},{self.screen}')
    
    mi5 = Mi(2000,15)
    ip7 = Iphone(4000,4)
    mi5.show()
    ip7.show()
    
    HOST = '127.0.0.1'
    PORT = 3306
    DB_PATH = 'ss'
    
    import uuid
    import pickle
    import os
    
    class MySQL:
        def __init__(self,host,port):
            self.host = host
            self.port = port
            self.id = self.create_id()
    
        def save(self):
            if not self.is_exists:
                raise PermissionError('id has existed')
            file_path = f'{DB_PATH},{os.sep}{self.id}'
            pickle.dump(self,open(file_path,'wb'))
        
        @property    
        def is_exists(self):
            tag = True
            files = os.listdir(DB_PATH)
            for file in files:
                file_abspath = f'{DB_PATH}{os.sep}{file}'
                obj = pickle.load(open(file_abspath,'rb'))
                if self.host == obj.host and self.port == obj.port:
                    tag = False
                    break
            return tag
        
        @staticmethod
        def get_obj_by_id(id):
            file_abspath = f'{DB_PATH}{os.sep}{id}'
            return pickle.load(open(file_abspath,'rb'))
        
        @staticmethod
        def create_id():
            return str(uuid.uuid1())
        
        @classmethod
        def from_conf(cls):
            print(cls)
            return cls(HOST,PORT)
        
        conn = MySQL.from_conf()
        conn.save()
        
        conn1 = MySQL('127.0.0.1',3306)
        conn1.save()
        
        obj = MySQL.get_obj_by_id()
        print(obj.host)
            
    
  • 相关阅读:
    北京西格玛大厦微软社区精英 Visual Studio 2010 技术交流会记录
    2010522 Windows Phone 开发者日
    SharePoint Server 2010 RTM 安装过程(图)
    Windows HPC Server 2008 R2 简体中文版 下载
    转:Community Clips 使用指南
    关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files… ‘Access is denied.’ 的解决办法
    岗位职责
    PowerPoint 2010 的广播幻灯片功能尝试了一下,可以用。
    Silverlight 4 五
    Windows Server AppFabric 简体中文 下载地址
  • 原文地址:https://www.cnblogs.com/agsol/p/11656491.html
Copyright © 2011-2022 走看看