python 随笔(property & __class__)
1. 属性装饰器:
property
@property def errors(self): """ Returns a list of form.errors for every form in self.forms. """ if self._errors is None: self.full_clean() return self._errors
cached_property
@cached_property def forms(self): """ Instantiate forms at first property access. """ # DoS protection is included in total_form_count() forms = [self._construct_form(i) for i in xrange(self.total_form_count())] return forms
2. 对象的父类名称
对象所属的类: object.__class__
cls.__bases__ (因为父类可能不止一个,所以复数)
因此对象的父类名称为集合: [x.__name__ for x in object.__class__.bases__]