Re: Using inner dict as class interface

2013-01-16 Thread Peter Otten
Steven D'Aprano wrote: > On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > >> 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 lik

Re: Using inner dict as class interface

2013-01-16 Thread Dave Angel
On 01/16/2013 09:42 AM, Florian Lindner wrote: 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: Is it a specific requirement that

Re: Using inner dict as class interface

2013-01-16 Thread Matt Jones
Or do what Steven said if its exactly a dict and doesn't require special management of the underlying dict. *Matt Jones* On Wed, Jan 16, 2013 at 8:58 AM, Matt Jones wrote: > Explicit is better than implicit. Define the dunder methods so you know > exactly what your class is doing when being in

Re: Using inner dict as class interface

2013-01-16 Thread Matt Jones
Explicit is better than implicit. Define the dunder methods so you know exactly what your class is doing when being indexed. You only need __getitem__ and __setitem__ really, but if you want to treat it just like a dict you'll need __delitem__, __len__, __iter__, __contains__ as well. *Matt Jone

Re: Using inner dict as class interface

2013-01-16 Thread Steven D'Aprano
On Wed, 16 Jan 2013 15:42:42 +0100, Florian Lindner wrote: > 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. Then make it a d

Using inner dict as class interface

2013-01-16 Thread Florian Lindner
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