From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-10-30 15:45:19
David Abrahams, C++ library designer for hire
C++ Booster (http://www.boost.org)
----- Original Message -----
From: "Phil Austin" <paustin_at_[hidden]>
Sent: Tuesday, October 30, 2001 3:28 PM
Subject: Re: [boost] Boost Python: how to get at instance __dict__?
> David Abrahams writes:
> > Phil,
> > The instance's __dict__ can be accessed by writing instance.__dict__. I
> > guessing that your "attribute_set" is a data member of HDFFile. If you
> > attribute values in there, they won't show up in the __dict__. Your
> > members don't show up in the __dict__ either (they're C++ objects, not
> > Python objects of course). Maybe the best way to illustrate is with
> > Python code analogous to what you've done:
> > Why are you storing attributes in your own attribute_set? The instance
> > already has a __dict__ !
> A little background might help here. We'd like to produce a boost
> interface to a file format called HDF (NCSA hierarchical data format)
> that has the same api as Konrad Hinsen's NetCDF (NCAR common data
> format) module
> (http://dirac.cnrs-orleans.fr/programs/scientific.html). Both these
> file formats store data (binary arrays) and metadata (strings and
> arrays that describe the data). Hinsen's module generates file
> objects and variable objects that map file and variable metadata onto
> file and variable instance attributes. The variable instances support
> slicing, so you can store and retrieve partial N-dimensional
> arrays. In essence we're pickling/unpickling the instance, with HDF
> and netCDF being the pickle data formats.
Thanks for all the background, Phil, but it does nothing to clarify why you
want to store attributes anywhere other than the instance's dict.
> So in Python I can see it's no problem to do something like:
> class HDFFile:
> def close(self):
Right, no problem.
> what I haven't been able to come up with is the Boost equivalent
> for the above.
If you use the technique normally applied to classes with virtual functions
that may be overridden in Python (see the boost.python docs for this), you
can end up with a pointer to the Python object in the object it contains.
From there you can use PyGetAttrString(self, "__dict__") to access the dict.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk