Dict/List manipulation from C

Richard Harvey tririch at connect.net
Thu Aug 24 09:12:26 EDT 2000


I'm sure what I'm needing is simple, I must just be missing it somewhere.
There seems to be some fairly basic yet critical functions missing for
manipulating Dictionaries and Lists through the Python 'C' libraries.  The
two needs I have are:

(1) Replacing the contents of one dictionary with the contents of another.
This is the case when I pass a dictionary from Python to my C code, using
the dictionary as a "keyed" structure.  Through other subsequent calls I
create a new dictionary with matching entries, and want to return this back
to the caller.  Right now I'm having to retrieve the (key,value) list, then
loop through each entry in the passed dictionary calling SetItem(key,value).
Seems a bit of overkill when in Python itself I can just say dict1 = dict2.

(2) Removing all entries from a list. Actually my "real" need is to
completely override the default search path for Python.  Right now I'm
inserting two additional paths to the head of the Python 'path' list, but
what I would rather do is remove all existing entries from the list then add
my two entries.  I can see no way to remove list entries from the 'C' side.
But, if anyone can tell me a better way to override the Python path without
mucking with this variable, that would be great too!

Thanks for any help,
Rich






More information about the Python-list mailing list