python , Boost and straight (but complex) C code



I have these pieces of C-code (NOT C++ !!) I want to call from Python.
I found Boost.
I have MS Visual Studio 2005 with C++.

is this the idea:
I write the following C source file:
============================
#include <iostream>
#include <stdafx.h>

namespace { // Avoid cluttering the global namespace.

int my_int; /* a global integer: or outside namespace ? */
double calc ( double f)
{
my_int = (int) (f/2);
printf( "Half of %f is %d\n", f, my_int );
return f/2;
}

}

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE( half )
{
def("calc", calc );
}

================================

Which I put in a VC project and compile into a .DLL
This DLL I put somewhere on my disk, where Python 2.4 can find it.
then I write the following Python source:
=====================
from half import *
calc(34655.0)

et voila ?

Can I acces my_int too, this way ?

.



Relevant Pages

  • Re: Project organization and import
    ... I feel like the Python package system, ... Namespace. ... filesystem heirarchy. ... or forced to use "from foo import *". ...
    (comp.lang.python)
  • Re: How to import only one module in a package when the package __init__.py has already imports the
    ... Do you understand that each function has it's own local namespace? ... This is a constrain imposed by python. ... Because of this constraint in python. ... move it to a better package). ...
    (comp.lang.python)
  • Re: creating class objects inside methods
    ... Say you went to another country, where the people wore lead shoes, ... Python's namespace and object models, and so you have little standing ... the Python maintainers are very particular to define "bug" as ... And if you say, "Well you should be able to customize assigment", my ...
    (comp.lang.python)
  • Re: import vs from module import : any performance issue?
    ... When a line of code asks for the value of a variable x, Python will search ... local namespace - specific to the current function or class method. ... this and stop searching. ... > subsequent imports are essentially lookups in sys.modules. ...
    (comp.lang.python)
  • Re: organizing your scripts, with plenty of re-use
    ... Hierarchical choices are done on todays knowledge, ... this is just incorrect thinking and if one's programming in Python needs to be excised. ... Every package creates a namespace of objects it contains; those objects are modules. ...
    (comp.lang.python)