   Python/SWIG equivalent of lua_pcall?
  Does SWIG provide any helpers to facilitate invoking Python code from C++? I need to call a Python function (including parameters) from with my C++ (Python is embedded). I know I can execute a string of python commands but this doesn't let me pass parameters. I guess I'm looking for the equivalent of lua_pcall but I just don't see it - I must be blind or stupid! Thanks   
  The Python C API functions for calling Python functions are Py_ObjectCall(), PyObject_CallObject(), PyObject_CallFunction(), PyObject_CallMethod(), PyObject_CallFunctionObjArgs() and PyObject_CallMethodObjArg(). I'm not familiar with SWIG, so I don't know if it provides any wrappers for these functions.   ;  Thanks!I have the following code:#define PYTHON_MOD_NAME    "test"#define PYTHON_FUNC_NAME    "myfunc"module = PyImport_ImportModule(PYTHON_MOD_NAME);if (!module){printf("Error -- unknown module\n");}else if (PyObject_HasAttrString(module, PYTHON_FUNC_NAME)){printf("Finding function\n");function = PyObject_GetAttrString(module, PYTHON_FUNC_NAME);if (PyCallable_Check(function)){printf("Calling function\n");result = PyObject_CallFunction(function, "i", aNumber);cresult = PyLong_AsLong(result);}else   {  printf("Error -- attribute is not a function/method\n");   }}else{printf("Error -- Module does not contain \"%s\" function.\n", PYTHON_FUNC_NAME);}The Python file test.py contains:print "Module imported"def myfunc(aa):print "In function " + str(aa)When I run I get the error "Error -- Module does not contain "myfunc" function.". I can't see what I'm doing wrong. I'm assuming the module is being imported - it's in the same directory as the executable. Any ideas?Thanks again;  I even tried building this:http://www.python.org/doc/2.5.2/ext/run-func.txtbut it doesn't find the function in the file test.py:def func(aa):    print "In function " + str(aa);  There's a non-zero chance that when you import a module called "test" what's actually happening is that you're loading the Python standard test module, which does not contain an entity called "myfunc". Try renaming your module and trying again.   ;  Oh you have to be kidding me!! :)Thanks.   ;  This is what I'm trying to prototype:I have a C++ class Person, exposed to Python using SWIG. I have the following Python file:import persondef foo(aa):    print "In function " + str(aa)    person = Person()    return 9The C++ executable invokes the Python function foo(10), and the Python creates an instance of the Person class.Sounds reasonable I think? I'm getting a crash in the Python at "import person".   ;  What kind of crash? Is it in the Python side or the C++ side? Did you try PyErr_Print() to see what it displays?   ;  Error -- unknown moduleException exceptions.ImportError: 'No module named _person' in 'garbage collection' ignoredFatal Python error: unexpected exception during garbage collectionThe "import person" failed in my Python script and the crash is during Py_Finalize().   ;  Here are the source files. All the .h and .cpp files (including the one generated by swig) are linked into the executable. Should person.cpp, person.h and person_wrap.cxx (swig file) be in a DLL, or can they be used in the executable this way?Thanksmain.cpp// python1.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "python.h"#include "person.h"#define PYTHON_MOD_NAME    "mike"#define PYTHON_FUNC_NAME    "foo"int _tmain(int argc, _TCHAR* argv[]){PyObject * module;    PyObject * function;    PyObject * result;PyObject * dict;PyObject * module_name;    long cresult;int aNumber=10;Py_Initialize();Person p;printf("Importing module\n");module_name = PyString_FromString(PYTHON_MOD_NAME);module = PyImport_Import(module_name);if (!module){printf("Error -- unknown module\n");}else{printf("Finding function\n");dict = PyModule_GetDict(module);   function = PyDict_GetItemString(dict, PYTHON_FUNC_NAME);if (PyCallable_Check(function)){printf("Calling function\n");result = PyObject_CallFunction(function, "i", aNumber);cresult = PyLong_AsLong(result);}else   {  printf("Error -- attribute is not a function/method\n");   }}Py_Finalize();return 0;}person.h#pragma once#include "stdafx.h"class Person{public:Person(void);public:virtual ~Person(void);virtual int GetAge();virtual void SetAge(int age);protected:int_age;};person.cpp#include "StdAfx.h"#include "Person.h"#include <iostream>Person::Person(void){std::cout << "Person::Person" << std::endl;}Person::~Person(void){}int Person::GetAge(){return _age;}void Person::SetAge(int age){_age = age;}person.i%module person%{#include "person.h"%}class Person{public:virtual int GetAge();virtual void SetAge(int age);};mike.pyimport persondef foo(aa):    print "In function " + str(aa)    person = person.Person()    return 9