[Pyrex] modules

Elias Pschernig elias at users.sourceforge.net
Fri Dec 2 21:07:54 CET 2005


How can I create modules?

Like, I have:

---- foo/a.pyx ----
def init():
    pass

---- foo/b.pyx ----
def init():
    pass

And later from python, I want to access it as:

foo.a.init()
foo.b.init()

The problem is, if I just build it the standard way, distutils gives me
a foo/a.so and a foo/b.so, and it works like I want - but then, both
a.so and b.so are now linked to my external library, and therefore all
global variables in that library get duplicated (took me some time to
figure out that was the reason it fails).

I'm not sure what to do now.. either I need to somehow tell disutils to
not duplicate global variables, but I have no idea about that at all -
or I need to somehow create the submodules "a" and "b" of "foo" by
hand.. but I have no idea about that as well.

Simply writing "def a.init()" inside a foo.pyx doesn't work of course..
but that's all I could think of trying.

Any ideas?

-- 
Elias Pschernig




More information about the Pyrex mailing list