先定義一個類:
class Point():
? def __init__(self, x, y):
? ? ? self.x = x
? ? ? self.y = y
生成新對象:
1、point = Point(1, 2)
2、point = eval("{},({},{})".format("Point", 1,2))
3哈雏、point = globals()["Point"](1, 2)
4散址、point = locals()["Point"](1, 2)
5脆淹、point = getattr(sys.modules[__name__], "Point")(1, 2)
6巾钉、point = copy.deepcopy(point)
7、point = point.__class__(1, 2)
8坯约、point = type("Point", (Point, ),{})(1, 2)
9熊咽、point = type.new_class("Point", (Point, ),{})(1, 2)