Overloadable Assignment PEP
drew at astro.pas.rochester.edu
Fri Apr 4 05:39:14 CEST 2003
Lulu of the Lotus-Eaters <mertz at gnosis.cx> wrote in message news:<mailman.1049398267.20730.python-list at python.org>...
> drew at astro.pas.rochester.edu (Drew Moore) wrote previously:
> |voltage += 5 # (raise the voltage by 5 volts)
> |voltage *= 2 # (double the current voltage)
> |voltage = 3 # (set the voltage to 3 volts)
> |my voltage object is clobbered with an integer object.
> The case makes sense... but IMO, not nearly enough to change the
> behavior of assignment.
> For this particular case, you could simply coopt the meaning of some
> other augmented operator to set voltage. For example:
> voltage |= 3
> The need to bitwise-and on voltage seems unlikely, so you should not
> step on anything important. Of course, experienced Python programmers
> might do a little double take on the meaning, but documentation can
> explain it.
> Then again, I wouldn't mind adding the new operator ":=" which was
> "generic augmentation"... the operator could do -absolutely nothing- for
> standard types, but could be available for custom meaning in custom
> Yours, Lulu...
Use a different operator? not a bad idea..
I been there.. kinda. I used
voltage << 3
which was a little more intuitive to me syntactically..
However I still found myself accidentally typing
voltage = 3 every once in a while, as that makes the most "sense."
More information about the Python-list