CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/公开课/文档/年薪50W+的Python程序员如何写代码/code/Python/opencourse/part01/example09.py
Views: 729
1
import copy
2
3
4
class PrototypeMeta(type):
5
6
def __init__(cls, *args, **kwargs):
7
super().__init__(*args, **kwargs)
8
cls.clone = lambda self, is_deep=True: \
9
copy.deepcopy(self) if is_deep else copy.copy(self)
10
11
12
class Student(metaclass=PrototypeMeta):
13
pass
14
15
16
stu1 = Student()
17
stu2 = stu1.clone()
18
print(stu1 == stu2)
19
print(id(stu1), id(stu2))
20
21