translating "setattr" to C++

Thomas Heller theller at python.net
Fri Mar 19 17:50:26 EST 2004


danb_83 at yahoo.com (Dan Bishop) writes:

> Eric <eric at lentil.com> wrote in message news:<87oeqtkruw.fsf at subopt.austin.rr.com>...
>> Slightly off topic, i know, but here goes:
>> 
>> I'm trying to xlate a module of mine to C++. Only problem is, it makes
>> heavy use of "setattr". Anyone know a straightforward way to do
>> "setattr" in C++ ?
>
> No, but there's a workaround.
>
> Instead of referring to the fields of an object as, for example, x.foo
> and x.bar, store your object's data in a hash table with "foo" and
> "bar" as keys.

You could even store the hash table as a __dict__ instance variable in
your C++ object.  And use a PyDict_Object instead of the has table.

;-)

Thomas





More information about the Python-list mailing list