57 if (!module)
return false;
60 return instanciate (module, file, classname, args);
68 if (!module)
return false;
71 PyObject *reload = PyImport_ReloadModule (module);
73 if (!reload)
return false;
75 return instanciate (reload, file, classname, args);
79 bool py_object::instanciate (PyObject *module,
string file,
string classname, PyObject * args)
84 PyObject * classobj = PyObject_GetAttrString (module, (
char *) classname.c_str ());
93 Instance = PyObject_CallObject (classobj, args);
102 Classname = classname;
110 PyObject *result = NULL;
114 PyObject *tocall = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
116 if (PyCallable_Check (tocall) == 1)
118 result = PyObject_CallObject (tocall, args);
133 return PyObject_HasAttrString (
Instance, (
char *) name.c_str ());
142 return PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
152 PyObject *attribute = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
153 if (!attribute)
return 0;
155 s_int32 value = PyInt_AsLong (attribute);
156 Py_DECREF (attribute);
169 PyObject *attribute = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
170 if (!attribute)
return 0;
172 string value = PyString_AsString (attribute);
173 Py_DECREF (attribute);
185 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), value) == -1)
195 PyObject *val = PyInt_FromLong (value);
197 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), val) == -1)
210 PyObject *val = PyString_FromString (value.c_str ());
212 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), val) == -1)