List operator overloading snag
Peter Otten
__peter__ at web.de
Sun Apr 25 13:54:16 EDT 2004
Steven Brent wrote:
>>>> print S1 or S2
> Set: ['s', 'p', 'a', 'm'] # custom __repr__ used but still default
> # __or__ behavior, returns first true operand
>
>>>> print S1.__or__(S2)
> using Set.__or__
> Set: ['s', 'p', 'a', 'm', 'c', 't'] # now all the custom behaviors
Try S1 | S2 instead, __or__() somewhat misleadingly implements the | aka
"bitwise or" operator.
Peter
More information about the Python-list
mailing list