Attributes of builtin/extension objects

George Sakkis gsakkis at rutgers.edu
Wed Nov 2 10:14:16 CET 2005


Hi all,

I have a few questions on object introspection of builtins and
extension modules. Here's an example:

>>> from datetime import date
>>> d=date(2003,1,23)
>>> d.__dict__
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'datetime.date' object has no attribute '__dict__'
>>> d.__slots__
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: 'datetime.date' object has no attribute '__slots__'
>>> dir(d)
['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__ge__',
'__getattribute__', '__gt__', '__hash__', '__init__', '__le__',
'__lt__', '__ne__', '__new__', '__radd__', '__reduce__',
'__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__str__',
'__sub__', 'ctime', 'day', 'fromordinal', 'fromtimestamp',
'isocalendar', 'isoformat', 'isoweekday', 'max', 'min', 'month',
'replace', 'resolution', 'strftime', 'timetuple', 'today', 'toordinal',
'weekday', 'year']

- Where do the attributes of a datetime.date instance live if it has
neither a __dict__ nor __slots__ ?
- How does dir() determine them ?
- dir() returns the attributes of the instance itself, its class and
its ancestor classes. Is there a way to determine the attributes of the
instance alone ?

TIA,
George




More information about the Python-list mailing list