[Pyrex] Problems with cimport

Francesc Alted falted at openlc.org
Tue Nov 11 20:17:50 CET 2003


Hi,

I want to split my Pyrex module in several files as it is getting fatter and
fatter. I want to make use of the cimport feature introduced in 0.8 version,
but I'm having problems with it.

I've tried one of the small examples in the documentation, and, after make
some fixes (the example in tutorial seems untested), I ended with the next:

--begin file dishes.pxd--
cdef enum otherstuff:
    sausage, eggs, lettuce

cdef struct spamdish:
    int oz_of_spam
    otherstuff filler
--end file dishes.pxd--

--begin file restaurant.pyx--
cimport dishes
from dishes cimport spamdish

cdef void prepare(spamdish *d):
    d.oz_of_spam = 42
    d.filler = dishes.sausage

def serve():
    cdef spamdish d
    prepare(&d)
    print "%d oz spam, filler no. %d" % \
         (d.oz_of_spam, d.filler)
--end file restaurant.pyx--

after compiling it, it produces the next exception when executed:

>>> import restaurant
>>> restaurant.serve()
Exception exceptions.NameError: 'dishes' in 'restaurant.prepare' ignored
42 oz spam, filler no. 135220864
>>>

I'm using Pyrex 0.9 and Python 2.3 (but the same happens with python 2.2).

Any hint?. Thanks,

-- 
Francesc Alted





More information about the Pyrex mailing list