Dynamic attribute introspection
Roman Suzi
rnd at onego.ru
Tue Aug 14 00:56:03 EDT 2001
On Tue, 14 Aug 2001, Guido van Rossum wrote:
>please refer to the tutorial at http://python.org/2.2/descrintro.html.
Well. Here we see "register" keyword equivalent:
This is not always what you want; in particular, using a separate
dictionary to hold a single instance variable doubles the memory used
by a defaultdict instance compared to a regular dictionary instance.
There's a way to avoid this:
class defaultdict2(dictionary):
__slots__ = ['default']
def __init__(self, default=None):
...(like before)...
The __slots__ declaration takes a list of instance variables, and
reserves space for exactly these in the instance. When __slots__ is
This, without any sarcasms, suggests Python is moving toward
declarations.
I cant see why __dynamic__ must be used when classes can be
non-dynamic simply when they have __slots__.
While the builtin objects have slots anyway, why this low-level details
should be used outside the introspection context?
Sincerely yours, Roman Suzi
--
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Monday, August 13, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "I distinctly remember forgetting that." _/
More information about the Python-list
mailing list