can't add variables to instances of built-in classes

Chris Angelico rosuav at gmail.com
Sun Jul 17 08:02:31 EDT 2016


On Sun, Jul 17, 2016 at 9:50 PM, Wilson Ong <wilsonokw at gmail.com> wrote:
>> Use this feature sparingly, only when you know that there are going to be
>> many (millions rather than thousands) of Test instances.
>
> Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only?

"Pretty sure" isn't enough justification for a relatively meagre
saving of memory. Much easier to leave it flexible. It's only once the
memory saving stops being "relatively meagre" (for instance, with the
built-in 'str' type - there are a LOT of strings in a Python program,
since your variable names are stored as strings) that it's worth doing
that.

ChrisA



More information about the Python-list mailing list