Using inner dict as class interface
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jan 16 09:54:45 EST 2013
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 dict:
class C(dict):
def some_other_methods(self):
pass
my_dict = C(key="value") # or C({"key": "value"})
print len(my_dict)
print my_dict['key']
my_dict.some_other_methods()
--
Steven
More information about the Python-list
mailing list