It's excruciatingly obscure, but:
self.container.longVariableName.longName ^= -1
does the job, so long as the values you're dealing with are integers. "Are integers" is required so that there's an exploitable mathematical relation between the ~
and ^
operators.
Why it works:
- Bitwise complement is the same as xor'ing with an infinite string of 1 bits.
- Python maintains the illusion that integers use an infinite-width 2's-complement representation, so that -1 "is" an infinite string of 1 bits.