课后作业 day21

今日作业 day21

###第一题
import hashlib
import datetime
import os
import pickle

class MySQL:
    def __init__(self, host, port):
        self.id = self.create_id
        self.host = host
        self.port = port

    def create_id(self):
        m = hashlib.md5
        m.update(f'{datetime.datetime.now()}'.encode('utf8'))
        self.id = m.hexdigest()

    def save(self):
        if not self.is_exists:
            raise PermissionError('对象已存在!!')
        file_path = os.path.join(settings.DB_PATH, self.id)
        pickle.dump(self, open(file_path, 'wb'))

    def get_obj_by_id(id):
        file_path = os.path.join(settings.DB_PATH, id)
        return pickle.load(open(file_abspath,'rb'))
##第二题
import math

class Circle:
    def __init__(self,radius):
        self.radius = radius

    @property
    def area(self):
        return math.pi * self.radius**2

    @property
    def perimeter(self):
        return 2*math.pi*self.radius

c=Circle(10)
print(c.radius)
print(c.area)
print(c.perimeter) 
##第三题
import abc
import datetime
class Phone:
    @abc.abstractmethod
    def call(self):
        pass

    @abc.abstractmethod
    def check_time(self):
        pass

class Apple_phone(Phone):

    def call(self):
        pass

    def check_time(self):
        res = datetime.datetime.now()
        return res

iphone = Apple_phone()
print(iphone.check_time())
posted @ 2019-10-11 21:01  simple123  阅读(103)  评论(0编辑  收藏  举报