[Pyrex] instances of cdef'ed classes problem

Test Drive testdrive6 at gmail.com
Thu Jul 6 10:19:27 UTC 2006


taking the example from here:
http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/version/Doc/extension_types.html#CMethods

parrot.pyx
====================
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!"


cdef Parrot p1, p2
p1 = Parrot()
p2 = Norwegian()
print "p1:"
p1.describe()
print "p2:"
p2.describe()
====================

I created a shared lib named parrot.so and then  tried to import it

Python 2.4.3 (#1, May 31 2006, 15:15:15)
[GCC 3.3.5-20050130 (Gentoo 3.3.5.20050130-r1, ssp-3.3.5.20050130-1,
pie-8.7.7. on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import parrot
p1:
This parrot is resting.
p2:
This parrot is resting.
Lovely plumage!
>>> dir(parrot)
['Norwegian', 'Parrot', '__builtins__', '__doc__', '__file__', '__name__']
>>> p=parrot.Parrot()
>>> dir(p)
['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__new__', '__pyx_vtable__', '__reduce__', '__reduce_ex__',
'__repr__', '__setattr__', '__str__']
>>> dir(p.__pyx_vtable__)
[]
>>> p.decribe()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'parrot.Parrot' object has no attribute 'decribe'
>>>


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

TD
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.copyleft.no/pipermail/pyrex/attachments/20060706/719911dd/attachment.html 


More information about the Pyrex mailing list