[Pyrex] Cannot 'see' C methods in extension types
Nitin Madnani
nmadnani at wam.umd.edu
Thu Sep 29 05:47:47 CEST 2005
Hi Guys
I wanted to use C methods in my the extension types that I was using
and so I wrote this:
cdef class State:
cdef unsigned char cover_vector
cdef int last_eng_position
cdef readonly State prev_state
def __init__(self):
self.last_eng_position = -1
def __eq__(self, State other):
return self.cost == other.cost and self.cover_vector ==
other.cover_vector
def __ne__(self, State other):
return self.cost != other.cost and self.cover_vector !=
other.cover_vector
cdef set_prev_state(self, State s):
self.prev_state = s
A couple of questions:
1) When I try to call the C method from python, it complains:
AttributeError: 'State' object has no attribute 'set_prev_state'
Is there something that I am doing that is preventing me from using
these methods? The 'extension types' guide doesn't seem to say
anything else about it.
2) This code snippet:
from core import * # 'core' is the module that contains the
above pyrex code
s1 = State()
s2 = State()
s1 == s2 # returns False
s1.__eq__(s2) # returns 1
So what's going on here? Isn't the '==' operator supposed to call the
__eq__() method?
Thanks !
Nitin
More information about the Pyrex
mailing list