question on dict subclassing and overriding __setitems__

Eric S. Johansson esj at harvee.org
Tue Jun 13 19:18:47 EDT 2006


I apologize if this is an FAQ but googling has not turned up anything, 
at least to my keywords.

I need to parse a configuration file from an existing application and 
I'm treating it as a dictionary.  I created my class with a parent class 
of dict.  Everything works okay except I discover I need to force keys 
to uppercase when setting a value.

I override __setitems__ and, as you'd expect, I get a recursive loop. 
I'm obviously missing a clue on how to break the recursion.  My 
admittedly simpleminded method overloading looks like:

     def __setitem__ (self, index, value):
         """force keys to uppercase"""
         self[index.upper()] = value

thanks for any pointers.





More information about the Python-list mailing list