
At Tue, 21 Dec 2010 15:47:38 +0100, Ralf Goertz wrote:
Hi,
is it possible to have python have readonly access to class members that are non constant?
typedef map
Links; class DataSet { Links links; }
BOOST_PYTHON_MODULE(_boosttest) { class_<Links>("Links") .def(map_indexing_suite<Links>());
class_<DataSet>("DataSet") .def_readonly("links",&DataSet::links); }
Although DataSet.links is defined readonly I can change it from within python.
If you mean that you can do d = DataSet() d.links = 1 that would be a Boost.Python bug. If instead you mean that you can do d = DataSet() d.links["foo"] = "bar" that would be unsurprising (to me), intended behavior; that's just how the Python object model works.
What can I do to prevent python from overwriting links?
You could always do the equivalent of del DataSet.__dict__["__setitem__"] to disable it. -- Dave Abrahams BoostPro Computing http://www.boostpro.com