Method to create a class of type metaclass

First, the code

= class_name ' CAR ' 
dict_name = {} 
bases = (Object,) 

class_body = '' ' 
DEF the __init __ (Self, name): 
    the self.name = name 

DEF Driver (Self): 
    Print ('% S cars gone ', the self.name) 

'' ' 
# classes body content into namespace 
Exec (class_body, {}, dict_name)
 Print (dict_name) 
CAR = type (class_name, bases, dict_name)
 Print (CAR)

 

Guess you like

Origin www.cnblogs.com/angelyan/p/11374353.html