comparing dissimilar types?

Pete Shinners pete at visionart.com
Fri Oct 6 18:11:10 EDT 2000


i've got a handly 2D-point object written in my C extension.
it currently interacts well with other python sequences..

>>> p = mypoint(10, 15)
>>> p
<point(10, 15)>
>>> p + 5
<point(15, 20)>
>>> p - (5, 10)
<point(5, 5)>
>>> p[1] = 10
>>> p
<point(10, 10)>
>>> p == 10
1
>>> p == (10,10) #should result TRUE
0
>>> p[:] == [10,10] #TRUE because of list compare
1


what's strange is when i do "p==(10,10)", my coercion and
compare routines are not being called. when i do "p==10"
my coercion and compare do get called. all i can guess is
python is 'heading me off at the pass' be deciding i have
two sequence items.

in reality, i really don't care for the "p==10", and will
probably remove it. but i really want "p==(10,10)" to work.
is there any way i can convice python to call my
coercion/compare routines in this situation?






More information about the Python-list mailing list