[Pythonmac-SIG] libxml2 on 10.3 (Panther)
Jack Jansen
Jack.Jansen at cwi.nl
Wed Dec 3 07:19:13 EST 2003
On 3 Dec 2003, at 10:42, paul at donovansbrain.co.uk wrote:
> Hi,
>
> Despite the fact that 10.3 ships with libxml2, there doesn't appear to
> be
> a module to use it with Python 2.3 - 'import libxml2' says that the
> module
> doesn't exist.
>
> So, how do I get this working? Do I have to recompile libxml2? I'm a
> bit
> clueless when it comes to Python modules and the way they relate to
> other
> libraries.
Someone actually has to create the module first...
To use an existing C library from Python you need a wrapper module,
which
takes care of converting data representations from Python to C and vice
versa. This wrapper module is then what you import into Python.
Creating a wrapper module is not trivial, but there are some tools to
help
you with it. The most popular one is swig, which you feed modified .h
files
and which then spits out a set of Python and C modules that wrap the
library.
Swig will also create wrapper modules for Perl and other language.
An alternative is bgen, which is similar but more powerful (and
therefore more
complex to use).
You can also create the wrapper module by hand, in C, but this is a lot
of
boring work. creating the wrapper in Pyrex is a better alternative, as
Pyrex
is a sort of Python-C-hybrid that takes care of all the boring
boilerplate you
would otherwise have to write in C, but you still have to manually
write all
the wrapper.
--
Jack Jansen <Jack.Jansen at cwi.nl> http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma
Goldman
More information about the Pythonmac-SIG
mailing list