Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36897

Using inner dict as class interface

Date 2013-01-16 15:42 +0100
Subject Using inner dict as class interface
From Florian Lindner <mailinglists@xgm.de>
Newsgroups comp.lang.python
Message-ID <mailman.571.1358347369.2939.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Using inner dict as class interface Florian Lindner <mailinglists@xgm.de> - 2013-01-16 15:42 +0100
  Re: Using inner dict as class interface Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-16 14:54 +0000
    Re: Using inner dict as class interface Peter Otten <__peter__@web.de> - 2013-01-16 18:34 +0100

csiph-web