tags (space delimited): Introduction to the Meta-class
Meta-Class Introduction:
Before formally introducing the meta-class, we reserve a bit of knowledge: exec;
- The EXEC command uses
This command has three parameters:
1. Command in string form (extract string)
2. Global scope; (dictionary form, if not specified, Globals () is used by default)
3. Local scope, (in dictionary form, if default locals is not specified)
g={'x':1,'y':2}l={}exec("""global x,mx=10m=100z=3""",g,l)print(g)#print(l)
- exec is the execution of a function; Here you remember, we'll use it back.
Everything in Python is an object, how can objects be used?
1. All can be quoted; x=obj
2.2nd, can be used as the parameters of the function of the incoming;
3. Can be used as the return value of a function
4. Can be used as a container type of element; (that is, multiple values, such as dictionaries, lists)
class Foo:#类也是对象 passobj= Foo()print(type(obj))print(type(Foo))
Execution Result:
<class main,foo>
<class ' type ' >
- The concept of a meta-class:
To the above example can be found: Foo is also an object, in Python everything is an object, from here can be seen: class classes, is called meta-class: <class ' type ' >
As follows: is a Chinese class defined by a meta-class:
- Bottom line: The Meta class is the original class, which is the class class
Introduction to Object-oriented meta-class (not to be continued)