David Mertz added the comment:

Raymond wrote:
> The idea is that the method would return a new counter instance
> and leave the existing instance untouched.

Your own first example suggested:

    c /= sum(c.values())

That would suggest an inplace modification.  But even if it's not that, but 
creating a new object, that doesn't make much difference to the end user who 
has rebound the name `c`.

Likewise, I think users would be somewhat tempted by:

    c = c.scale_by(1.0/c.total)  # My property/attribute suggestion

This would present the same attractive nuisance.  If the interface was the 
slightly less friendly:

    freqs = {k:v/c.total for k, v in c.items()}

I think there would be far less temptation to rebind the same name 
unintentionally.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25478>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to