|
From: Fuzzyman <fuz...@vo...> - 2005-12-05 15:50:18
|
Matthew Brett wrote: >Hi, > > > >> for key, val in indict.items(): >> if key in self and isinstance(self[key], dict) and >> isinstance(val, dict): >> self[key].update(val) >> else: >> self[key] = val >> >> >> Just in case you try to overwrite a sub-section with a scalar value. >> >> > >So, for > >a.update(b) > >if a is a dictionary (subsection), and b is not, then won't a be >overwritten with the non-dictionary value? > > > I don't understand the question. You can only update from a dictionary (b must be a dictionary or a ConfigObj). If *inside* your dictionary a, one of the values is a dictionary (a subsection) - that can be overwritten if dictionary b has a scalar for that value. This should be the same result as for a dictionary. Can you show me an example (using the new code) that doesn't behave how you would expect ? >Does it matter that the update function works differently for the >configobj object and a dictionary? For example > >a.update(b) > >can give a different result for the same dictionary contents if a is >of type dict or type configobj, because the normal update method is >not recursive. > > > Because all subsections are instances of Section - the new method *is* recursive (it uses Section.update). All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml >Best, > >Matthew > > > |