How to create a unary operator?

Erik Max Francis max at alcyone.com
Tue Nov 5 16:38:55 EST 2002


Joe Sixpack wrote:

> Is it possible to create a unary operator on a class object by
> redefining an
> existing operator symbol?  If so, how?

Sorry, no.  In Python you can overload operators, but only preexisting
ones in the way they already work.  You could override unary negation,
for instance, but you can't make bitwise xor act as a unary operator or
introduce a brand new binary operator like @.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ It is one thing to praise discipline, and another to submit to it.
\__/ Cervantes
    Rules for Buh / http://www.alcyone.com/max/projects/cards/buh.html
 The official rules to the betting card game, Buh.



More information about the Python-list mailing list