Hi, I'm trying to instrument a wrapped class with custom __setattr__ mechanics:
.def("__setattr__", &MyExtensionClass::setattr) How can I call the base class __setattr__ from within setattr and not run into infinite recursion? I.e. the analogon in C++ to >> class Foo(object): ... def __setattr__(self, attr, value): ... print "custom __setattr__" ... object.__setattr__(self, attr, value) ... >>> foo = Foo() >>> foo.x = 23 custom __setattr__ >>> foo.x 23 >>> To actually write to my instance dict I currently do PyObject* __dict__ = PyObject_GetAttrString(m_self, const_cast<char*> ("__dict__")); PyDict_SetItemString(__dict__, name, value.ptr()); inside MyExtensionClass::setattr (where m_self is PyObj*) Is there a better way? On a sidenote, I initially thought I could wrap the __dict__ in bp::dict() to use its nice Python-like API for item assignment but this seems to always make a copy of the __dict__. I.e something like bp::dict bp_dict(__dict__); bp_dict[name] = value; won't work. Regards Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig