[Python-ideas] Augmented assignment syntax for objects.

Erik python at lucidity.plus.com
Wed Apr 26 15:41:14 EDT 2017


On 26/04/17 18:42, Mike Miller wrote:
> I want to be able to say:
>>
>> def __init__(self, foo, bar, baz, spam):
>>   self .= foo, bar, spam
>>   self.baz = baz * 100
>
>
> I don't see ALL being set a big problem, and less work than typing
> several of them out again.

Because, some of the parameters might be things that are just passed to 
another constructor to create an object that is then referenced by the 
object being created.

If one doesn't want the object's namespace to be polluted by that stuff 
(which may be large and also now can't be garbage collected while the 
object is alive) then a set of "del self.xxx" statements is required 
instead, so you've just replaced one problem with another ;)

I'd rather just explicitly say what I want to happen rather than have 
*everything* happen and then have to tidy that up instead ...

E.


More information about the Python-ideas mailing list