[Pyrex] A "main" function for Pyrex: cimport does not work
Alain Pointdexter
alainpoint at yahoo.fr
Fri Apr 15 06:40:55 CEST 2005
--- len-l at telus.net a écrit :
> This simple example taken from the Pyrex docs ran
> for me:
>
> ============ dishes.pxd =================
> cdef enum otherstuff:
> sausage, eggs, lettuce
>
> cdef struct spamdish:
> int oz_of_spam
> otherstuff filler
> ============ restaurant.pyx ===============
> include "main.pxi"
>
> 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)
>
> def main(arglist):
> serve()
> return 0
> =========================================
>
> dishes.pxd and restaurant.pyx were in the same
> directory.
Thank you for responding so quickly Lenard. I've just
tried your example. I entered the following commands:
pyrexc restaurant.pyx
gcc -c restaurant.c -I/usr/local/Python-2.2.2/Include
-D__pymoduleinit__=initrestaurant
pyrexc dishes.pyx
gcc -c dishes.c -I/usr/local/Python-2.2.2/Include
gcc -o restaurant restaurant.o dishes.o
-L/usr/local/Python-2.2.2 -lpython2.2 -ldl -lpthread
-lutil -lm -D__pymoduleinit__=initrestaurant
I tried it on the command line and i get the
following:
$ restaurant
Exception exceptions.NameError: 'dishes' in
'restaurant.prepare' ignored
42 oz spam, filler no. 135414616.
The 'cimport dishes' didn't work but strangely enough
'from cdishes import spamdish' did !!
I tried it again by replacing 'cimport dishes' with
'from dishes cimport sausage' and then i get the
correct result: '42 oz spam, filler no. 0.'
I am puzzled about why this doesn't work!
Thank you for helping
Alain
__________________________________________________________________
Découvrez le nouveau Yahoo! Mail : 250 Mo d'espace de stockage pour vos mails !
Créez votre Yahoo! Mail sur http://fr.mail.yahoo.com/
More information about the Pyrex
mailing list