[Pyrex] Namespaces, modules and includes - oh my!

Gavin Baker gavinb at gmail.com
Thu Feb 3 03:38:30 CET 2005


Hello Greg,

On Fri, 28 Jan 2005 22:55:21 +1300, Greg Ewing
<greg.ewing at canterbury.ac.nz> wrote:
> Gavin Baker wrote:
> > In a nutshell, the problem is that types included via "include" in two
> > separate modules are not regarded as the same when one module calls
> > cdef methods that use these included types in the other.
> 
> You shouldn't be using include for that. You should be
> defining the shared types in a .pxd file and using
> cimport to import them.

Aha - that makes much more sense now!

> This is more or less right, except that the owning
> module doesn't need to be a real module. It's possible
> to have a .pxd file serving purely as a namespace for
> declarations, without any corresponding .pyx file.

That is the key insight - all the docs I had seen seemed to imply a
.pxd had to go with a .pyx.

> In your example, all you need to do is rename 'stdio.pxi'
> to 'stdio.pxd', and cimport FILE from that in each .pyx
> file where you need it.

Thanks for your help - I have updated the test case, which of course
now succeeds, and now changed my project accordingly.  It all works
beautifully.

Thanks & regards -
 
  :: Gavin



More information about the Pyrex mailing list