[Python-ideas] Augmented assignment syntax for objects.

Erik python at lucidity.plus.com
Tue May 2 18:55:48 EDT 2017


On 26/04/17 21:50, Chris Angelico wrote:
> On Thu, Apr 27, 2017 at 6:24 AM, Erik <python at lucidity.plus.com> wrote:
>> The background is that what I find myself doing a lot of for private
>> projects is importing data from databases into a structured collection of
>> objects and then grouping and analyzing the data in different ways before
>> graphing the results.
>>
>> So yes, I tend to have classes that accept their entire object state as
>> parameters to the __init__ method (from the database values) and then any
>> other methods in the class are generally to do with the subsequent analysis
>> (including dunder methods for iteration, rendering and comparison etc).
>
> You may want to try designing your objects as namedtuples. That gives
> you a lot of what you're looking for.

I did look at this. It looked promising.

What I found was that I spent a lot of time working out how to subclass 
namedtuples properly (I do need to do that to add the extra logic - and 
sometimes some state - for my analysis) and once I got that working, I 
was left with a whole different set of boilerplate and special cases and 
therefore another set of things to remember if I return to this code at 
some point.

So I've reverted to regular classes and multiple assignments in __init__.

E.



More information about the Python-ideas mailing list