PEP 312 (and thus 308) implemented with a black magic trick

Alex Martelli aleax at aleax.it
Tue Mar 18 16:07:10 CET 2003


Erik Max Francis wrote:
   ...
> Furthermore, if you change the meaning of ~, what operator now becomes
> used to represent bitwise negation?

Why, the
    -1^
"operator", of course -- or the
    -1-
"operator", as a roughly equivalent alternative -- after all,

    assert ~x == -1^x == -1-x

innit...?  Using ^ has the advantage of raising TypeError when ~ would
(I think), while - would be more permissive.


Alex





More information about the Python-list mailing list