1104 Review

Yesterday Review

exec

May be added to the code string of python global / local namespace.

Moto类

What is the metaclass

Yuan class is the class of the class, type of class is a metaclass

Use object metaclasses

Creating and call control class

How to write a metaclass

Custom metaclass

自定义一个类,继承type
type 内部触发了call,然后调用new创建一个空对象,将空对象以及括号内所有的参数一并传给__init
def __call__() ----  def __new()__()   --- def__init__

How meta-class references to the need metaclass

class类(metaclass = 元类名)

Manually create class

Call type

类名,基类父类,类的名称空间

4. The data items Youku layer

ATM

    dict--json
    优点:
        跨平台,速度快

subject system

    对象 -- bytes  --  pickle

​   优点:可以通过对象.属性的方式存值

Youku system

    集成ATM + 选课系统的优点
    存值:
        对象 -- dict -- pymysql -- MySQL
    取值:
        MySQL  --  pymysql --  dict  --- 对象
    封装ORM:
    
        1.字段类型
        -Field
        name/column_type/primary_key/default
            -string
            -integer
            
        2.写models类
        -继承dict
            可以接受任意个数的关键字参数
            问题:字典无法通过队形啊.属性的方式存取值
            解决: 在MOdels类中__setattr__,__getattr__
                __setattr__(self,key,value)
                    self[key] = value
                __getattr__(self,item)
                    return self.get(item)
                    
        3.写元类
            - 继承type类
                1.获取一张表名
                2.判断数据表类中是否有一个唯一主键
                3.将所有字典类型都存入一个独立的mappings字典中
                    - 方便获取
                

SNAKE

增删改查
    - save: insert into...
    - del:  delete  ...
    - update: update set ...    
    - selete: select from...

Guess you like

Origin www.cnblogs.com/fwzzz/p/11802255.html