Overloading __getitem__

2008-05-22 Thread Andreas Matthias
The following code doesn't run but I hope you get what I am trying to do. class my_dict (dict): def __getitem__ (self, key, crazy = False): if crazy == True: return 5 * self.get(key) else: return self.get(key) foo = my_dict() foo['a'] = 123 print fo

Re: Overloading __getitem__

2008-05-22 Thread Andreas Matthias
[EMAIL PROTECTED] wrote: > actually i ddin't think about the fact that you're overloading dict, which > can already take multiple values in getitem Oh, I didn't know that. I totally misinterpreted the error message. > so how about > > class crazy: pass > > and then in your dict class: > > d