[Python-ideas] Augmented assignment syntax for objects.
Mike Miller
python-ideas at mgmiller.net
Wed Apr 26 13:42:03 EDT 2017
On 2017-04-25 15:30, Erik wrote:
> All of the decorators (or other language tricks that modify the object's dict)
> suggested so far assume that ALL of the method's arguments are to be assigned. I
> do not want that. 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.
Just because all args get set at once, doesn't mean the init stops there and
attributes can't be further modified or deleted. In your example above, you
modify baz afterward as an argument that might need to be changed, as they often do.
If this doesn't give enough control, the manual way is always available.
Setting them all makes simple things *very* simple, and the medium and
complicated still possible.
More information about the Python-ideas
mailing list