[Pyrex] Cannot 'see' C methods in extension types
Nitin Madnani
nmadnani at wam.umd.edu
Thu Sep 29 07:19:02 CEST 2005
Whoops !! Upon closer inspection of the guide, I realize that the C
methods are only meant to be called from Pyrex code. Sorry about that.
I still don't understand the different behaviors of __eq__() and
'==' , though.
Thanks again !
Nitin
On Sep 28, 2005, at 11:47 PM, Nitin Madnani wrote:
> 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
>
> _______________________________________________
> Pyrex mailing list
> Pyrex at lists.copyleft.no
> http://lists.copyleft.no/mailman/listinfo/pyrex
>
More information about the Pyrex
mailing list