把这个提到外面class __metaclass__(type):" simple custom metaclass to block adding new attributes to this class "__setattr__ = no_new_attributes(type.__setattr__)再在NoNewAttrs定义的地方加进去class NoNewAttrs(object, metaclass = __metaclass__):就可以了