@@ -5,11 +5,11 @@ In Python every class can have instance attributes. By default Python
55uses a dict to store an object’s instance attributes. This is really
66helpful as it allows setting arbitrary new attributes at runtime.
77
8- However, in small classes with known attributes it might be a
8+ However, for small classes with known attributes it might be a
99bottleneck. The ``dict `` wastes a lot of RAM. Python can’t just allocate
1010a static amount of memory at object creation to store all the
1111attributes. Therefore it sucks a lot of RAM if you create a lot of
12- classes (I am talking in thousands and millions). Still there is a way
12+ objects (I am talking in thousands and millions). Still there is a way
1313to circumvent this issue. It involves the useage of ``__slots__ `` to
1414tell Python not to use a dict, and only allocate space for a fixed set
1515of attributes. Here is an example with and without ``__slots__ ``:
@@ -19,9 +19,9 @@ of attributes. Here is an example with and without ``__slots__``:
1919.. code :: python
2020
2121 class MyClass (object ):
22- def __init__ (name , class ):
22+ def __init__ (name , identifier ):
2323 self .name = name
24- self .class = class
24+ self .identifier = identifier
2525 self .set_up()
2626 # ...
2727
@@ -30,10 +30,10 @@ of attributes. Here is an example with and without ``__slots__``:
3030.. code :: python
3131
3232 class MyClass (object ):
33- __slots__ = [' name' , ' class ' ]
34- def __init__ (name , class ):
33+ __slots__ = [' name' , ' identifier ' ]
34+ def __init__ (name , identifier ):
3535 self .name = name
36- self .class = class
36+ self .identifier = identifier
3737 self .set_up()
3838 # ...
3939
0 commit comments