[Pyrex] cimport

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Mar 7 03:08:37 CET 2005


William Stein wrote:

> In order to use cimport across directories 
> and have everything work correctly, I've noticed
 > that it's necessary to use
> exact notation, e.g., 
 >
 > cimport sage.rings.rational
> import sage.rings.rational
> 
> instead of
> 
> cimport rational
> import rational

It's not a good idea to try to trick your way around
that. Pyrex uses the full dotted name to tell where
abouts the module will be in the module namespace at
run time.

Why don't you want to use the full name? Keep in
mind that you can do things like

   cimport sage.rings.rational as rational

to give yourself a shorter way of referring to
it in the .pyx file. Also, you can use -i options
to specify directories to search for .pxd files,
so they don't all have to be in the same directory.

You can symlink the dotted name to something else
if you like, but Pyrex must be given the dotted
name, not any other name.

> When including more than one cimport from another
 > directory, pyrexc complains about duplicate declarations.

Can you provide an example? As long as you haven't
lied in any way about the real name of the module,
Pyrex should keep their definitions in different
namespaces.

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+



More information about the Pyrex mailing list