cdef extern from "Python.h": void Py_Initialize() void Py_Finalize() void PySys_SetArgv(int argc, char **argv) cdef extern void initsnk() cdef public void snk_initialize (int argc, char **argv) : Py_Initialize() PySys_SetArgv(argc, argv) initsnk() cdef public void snk_finalize () : Py_Finalize() import sys global _error_name _error_name = "" global _error_message _error_message = "" # Exception exceptions.NameError: '_error_occurred' in 'snk.error' ignored # if the next line is: global _error_message # and if the line "sys = ..." below in _save_error() is not present # but, if "sys = ..." is present, using "global _error_message" here is OK cdef int _error_occurred _error_occurred = 0 # segfault if this function is def'ef instead of cdef'ed cdef void _save_error () : global _error_name, _error_message, _error_occurred cdef char *s # Exception exceptions.NameError: 'sys' in 'snk._save_error' ignored # if the next line is not present sys = __import__("sys") c, e, t = sys.exc_info() if e is None : _error_occurred = 0 else : _error_name = c.__name__ _error_message = str(e) _error_occurred = 1 cdef public int error () : global _error_occurred return _error_occurred cdef public char *error_name () : global _error_name return _error_name cdef public char *error_message () : global _error_message return _error_message import snakes.plugins # this build and return in snk a new module that is essentially the # same as snk.nets but with classes from snakes.plugins.pos, some # being new, others extend classes from snakes.nets snk = snakes.plugins.load("pos", "snakes.nets", "snk") cdef public object snk_new_Place (char *name, int x, int y) : try : # this will cause and error as pos should be (x,y) only return snk.Place(name, pos=(x, y, 42)) except : _save_error() cdef public char *snk_Place_str (object self) : cdef char *result try : s = self.__str__() result = s return result except : _save_error()