注意:Python3中不再有__metaclass__屬性以及模塊級別的__metaclass__屬性。如果一個模塊中函數(shù)較多,可以利用正則表達(dá)式進(jìn)行查找替換。
不過在平時的使用中,我發(fā)現(xiàn)了模塊級別有個__build_class__函數(shù),將其改為Author,就能達(dá)到模塊級別元類的效果。但具體有哪些副作用還不太清楚,慎用?。?!
代碼地址: LearnPython
最后再強(qiáng)調(diào)一遍:
Metaclasses are deeper magic that 99% of users should never worry about. If you wonder whether you need them, you don't (the people who actually need them know with certainty that they need them, and don't need an explanation about why).