how does SWIG work? how do i make a python module out of a c function?

Randall Hopper aa8vb at yahoo.com
Tue Mar 7 14:11:08 EST 2000


Shaun Hogan:

 |<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 |<HTML><HEAD>
 |<META content=3D"text/html; charset=3Diso-8859-1" =
 |http-equiv=3DContent-Type>
 |<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
 |<STYLE></STYLE>

Hi.  First, turn off HTML in your mailer (Microsoft Outlook Express I
gather).  You'll get more replies.  Many folks ignore or filter out posts
formatted with HTML.

 |   looking at [1]www.swig.org/tutorial.html
 |   
 |   i can see that this looks like what i need to do, however according to
 |   the tutorial "you need to write an "interface file" which is the input
 |   to SWIG.", then it gives an example interface file which looks okay to
 |   me to do, but my question is.....what application do i use to write
 |   this"interface file"?,

It's a text file.  So you can use any ASCII text editor you wish.  Since
you're on an MSWin box, use MSVC++, notepad, edit, whatever (just so long
as it's a text file when you're done).

 |   and what do i do with it when its wrote?,

You run "swig" on it.  SWIG generates wrapper code (in C, for example) and
optionally Python wrapper classes (.py) if you tell it to.  E.g. on UNIX:

     swig -shadow -python -I/my/includes -o stuff.i

 |   and what do i do with it when its wrote?

Link the wrapper code with the code it's wrapping, and then load it into
Python using a standard "import <module>" statement.  I could tell you
about UNIX, but you'll need to read the docs for MSWin directions.  This
should all be in the SWIG docs:

     http://sourceforge.net/project/?group_id=1645
     http://download.sourceforge.net/swig/

See the Doc/ tree in the package.

 |   how do i know if i have written it correctly?

Call your wrapped methods and test them?

 |   further down the page it shows (apparently) how to turn c code into a
 |   python module for Irix.....i dont know what that is, im using IDLE and
 |   windows.

See:
   http://starship.python.net/crew/mhammond/win32/BuildingExtensions.html
   

 |   can anyone help me, ive been stuck with this problem for a week...and
 |   im going mad trying to figure it out.

I'm not sure what you're stuck on yet.  Do you have an error message or
code snippet that's relevent?

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list