61 if (!module)
return false;
64 return instanciate (module, file, classname, args);
72 if (!module)
return false;
75 PyObject *reload = PyImport_ReloadModule (module);
77 if (!reload)
return false;
79 return instanciate (reload, file, classname, args);
83 bool py_object::instanciate (PyObject *module,
string file,
string classname, PyObject * args)
88 PyObject * classobj = PyObject_GetAttrString (module, (
char *) classname.c_str ());
97 Instance = PyObject_CallObject (classobj, args);
106 Classname = classname;
114 PyObject *result = NULL;
118 PyObject *tocall = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
120 if (PyCallable_Check (tocall) == 1)
122 result = PyObject_CallObject (tocall, args);
137 return PyObject_HasAttrString (
Instance, (
char *) name.c_str ());
146 return PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
156 PyObject *attribute = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
157 if (!attribute)
return 0;
159 s_int32 value = PyInt_AsLong (attribute);
160 Py_DECREF (attribute);
173 PyObject *attribute = PyObject_GetAttrString (
Instance, (
char *) name.c_str ());
174 if (!attribute)
return 0;
176 string value = python::as_string (attribute);
177 Py_DECREF (attribute);
189 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), value) == -1)
198 PyObject *val = PyInt_FromLong (value);
200 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), val) == -1)
213 PyObject *val = PyString_FromString (value.c_str ());
215 if (PyObject_SetAttrString (
Instance, (
char *) name.c_str (), val) == -1)