Using inner dict as class interface

Florian Lindner mailinglists at xgm.de
Wed Jan 16 09:42:42 EST 2013


Hello,

I have a:

class C:
   def __init__(self):
      d = dict_like_object_created_somewhere_else()

  def some_other_methods(self):
    pass


class C should behave like a it was the dict d. So I could do:

c = C()
print c["key"]
print len(c)

but also

c.some_other_method()

How can I achieve that? Do I need to define all methods like
__getitem__, __len__, ... (what else?) to access the inner dict or is
there something more slick?

Thanks,

Florian



More information about the Python-list mailing list