Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Python.h>
- void testfunc(PyObject *self, PyObject *args)
- {
- PyObject *obj;
- if (!PyArg_ParseTuple(args, "O", &obj))
- return NULL;
- PyStringObject *x;
- printf("A\n");
- x = PyObject_GetAttrString(obj, "x");
- printf("B %s\n",x->ob_sval);
- PyErr_Print();
- }
- static PyMethodDef testMethods[] = {
- {"myfunc", (PyCFunction)testfunc, METH_VARARGS, "."},
- {NULL, NULL},
- };
- PyMODINIT_FUNC
- inittestmod(void)
- {
- (void) Py_InitModule("testmod", testMethods);
- }
- -------------------------
- import new
- import testmod
- class Something(object):
- def __init__(self):
- self.func = new.instancemethod(testmod.myfunc, self, self.__class__)
- self.x = 'something'
- #Something.func = testmod.myfunc
- a = Something()
- print "Value returned should be:",a.x
- #testmod.myfunc(a)
- a.func()
- ------------------------
- Value returned should be: something
- A
- B something
Add Comment
Please, Sign In to add comment