[Pyrex] instances of cdef'ed classes problem
Stefan Behnel
behnel_ml at gkec.informatik.tu-darmstadt.de
Thu Jul 6 18:49:56 UTC 2006
Hi,
Test Drive wrote:
> if you see the above example.
The example below, you mean.
> You will notice what I am trying to do.
> So basically i am trying to create an instance of Parrot class.
Which is not the problem.
> We write python wrappers for libraries so that we can use it as it is
> just python code.
> In the above case I will not be able to create an instance of the Parrot
> class in the python world.
Sure, it works perfectly, as your example shows.
> Actually i am struck with such a piece of code in the very similar fashion.
> I have a cdef'ed class with mixed def'ed and cdef'ed functions.
> I am able to see and use def'ed functions however not cdef'ed functions.
That's normal. As I said, 'cdef' defines them as C functions, not Python
functions. Read the docs. If you want Python functions, do not use 'cdef'.
> And i donot see a trivial workaround for that code.
And I do not see the problem.
Stefan
> On 7/6/06, * Stefan Behnel* <behnel_ml at gkec.informatik.tu-darmstadt.de
> <mailto:behnel_ml at gkec.informatik.tu-darmstadt.de>> wrote:
>
> Hi!
>
> Test Drive wrote:
> > cdef class Parrot:
> >
> > cdef void describe(self):
> > print "This parrot is resting."
> >
> > cdef class Norwegian(Parrot):
> >
> > cdef void describe(self):
> > Parrot.describe(self)
> > print "Lovely plumage!"
> >
> > >>> p=parrot.Parrot()
> > >>> p.decribe()
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > AttributeError: 'parrot.Parrot' object has no attribute 'decribe'
>
> obviously :)
>
>
> > Now the problem is when i say dir(p)
> > i donot see the describe method, nor am i able to call it.
> > Is it not possible to create an instance of cdef'ed class?
> >
> > any clues?
> >
> > thanks in adavnce
>
> Check your spelling before complaining? :)
> Just kidding...
>
> Your method is a C method ("c"def!), so Python cannot see it. Make
> it a normal
> method without the "cdef" if you want to call it from Python.
>
> Stefan
>
>
More information about the Pyrex
mailing list