igor.kaist
А в чем разница?
в даному випадку нема: але є різниця для дескрипторів і атрибутів класу
[crchemist@test ~]$ cat ss.py
class A(object):
__slots__ = ('obj_attr_not_in_dict')
class_attr = 'i am class attr in class dict'
def __init__(self):
self.obj_attr_not_in_dict = 'i am object attr not in dict'
@property
def i_am_descriptor(self):
return 'i am not simple attr - i am descriptor'
[crchemist@test ~]$ python
Python 2.5.2 (r252:60911, Jul 5 2008, 03:54:54)
[GCC 4.3.0 20080428 (Red Hat 4.3.0-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ss import A
>>> a = A()
>>> a.__dict__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'A' object has no attribute '__dict__'
>>> a.obj_attr_not_in_dict
'i am object attr not in dict'
>>> a.__class__.__dict__.items()
[('__module__', 'ss'), ('i_am_descriptor', <property object at 0x956bd24>), ('class_attr', 'i am class attr in class dict'), ('obj_attr_not_in_dict', <member 'obj_attr_not_in_dict' of 'A' objects>), ('__slots__', 'obj_attr_not_in_dict'), ('__doc__', None), ('__init__', <function __init__ at 0x9569304>)]
>>> a.__class__.__dict__.get('i_am_descriptor')
<property object at 0x956bd24>
>>>