网站怎么做登录,深圳市升华建设有限公司网站,平台补单,人人秀h5制作教程暂时在工作中#xff0c;还没有用到呢~~~ 以后要留意一下#xff0c;主要用于复制对象副本#xff0c; 然后又有自定义属性的地方。 import copy
from collections import OrderedDictclass Book:def __init__(self, name, authors, price, **rest):self.name nameself.aut…暂时在工作中还没有用到呢~~~ 以后要留意一下主要用于复制对象副本 然后又有自定义属性的地方。 import copy
from collections import OrderedDictclass Book:def __init__(self, name, authors, price, **rest):self.name nameself.authors authorsself.price priceself.__dict__.update(rest)def __str__(self):mylist []ordered OrderedDict(sorted(self.__dict__.items()))for i in ordered.keys():mylist.append({}: {}.format(i, ordered[i]))if i price:mylist.append($)mylist.append(\n)return .join(mylist)class Prototype:def __init__(self):self.objects dict()def register(self, identifier, obj):self.objects[identifier] objdef unregister(self, identifier):del self.objects[identifier]def clone(self, identifier, **attr):found self.objects.get(identifier)if not found:raise ValueError(Incorrect object identifier: {}.format(identifier))obj copy.deepcopy(found)obj.__dict__.update(attr)return objdef main():b1 Book(The C Programming Language, (Brian W. Kernighan, Dennis M. Ritchie),price118, publisherPrentice Hall, length228, publication_date1978-02-22,tags(C, programming, algorithms, data stuctures))prototype Prototype()cid kr-firstprototype.register(cid, b1)b2 prototype.clone(cid, nameThe C Programming Language(ANSI, price48.99,publisherPrentice Hall, length274, publication_date1988-05-01, edition2)for i in (b1, b2):print(i)print(ID b1 : {} ! ID b2 : {}.format(id(b1), id(b2)))if __name__ __main__:main() 转载于:https://www.cnblogs.com/aguncn/p/9413565.html