不要在实例变量的开头使用双下划线,并且避免在开头和结尾使用它们,因为双下划线在python中有特殊的含义。
如果实例变量的标识符以双下划线开头,则它是“名称错位”以避免子类的名称空间中的冲突,因此self.__collections实际上变为self._Base__collections. 实例变量标识符开头和结尾的双下划线保留用于特殊方法和特殊名称(例如__add__or __class__)。
实例变量应该以字母(例如collections)或单个下划线开头,以表示它们是私有的(例如_collections)
无论如何,在您的示例中,您正在设置一个collection不存在的属性。如果您self.collection在Base类中命名该属性,它将正常工作。
说清楚:
>>> class Base(object):
...     def __init__(self, collection=None):
...             self.__collection__ = collection or self.__class__.__name__
... 
>>> class Thing(Base):
...     def __init__(self, **kwargs):
...             super(Thing, self).__init__()
...             self.__dict__.update(kwargs)
... 
>>> t = Thing(collection=3)   __dict__.update creates a new instance attribute
>>> t.__collection__
'Thing'
>>> t.collection   # here it is
3
>>> t = Thing(**{'__collection__': 7})   #UGLY! Do not do this!!!
>>> t.__collection__
7