How to create a unary operator?

Joe Sixpack joe.sixpack at whoopie.com
Tue Nov 5 12:54:00 EST 2002


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

For example, I'd like to create a new class, MyClass, and use the symbol '^'
to call a method in that class.  The '^' is a standard symbol in the domain
of the problem that I'm working in, so I'd like to use that symbol instead
of a different one, if at all possible.

Sample code that I'd like to be able to create and execute:

a = MyClass( )
b = ^a
if ^a:
    print 1
else:
    print 0

etc...

Thanks!
Sixpack





More information about the Python-list mailing list