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


Groups > comp.lang.python > #64382

Re: 1st Sketch at at ReadOnly dict

References <52DD8297.9050504@earthlink.net>
Date 2014-01-21 11:08 +1100
Subject Re: 1st Sketch at at ReadOnly dict
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5765.1390262921.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Tue, Jan 21, 2014 at 7:09 AM, Charles Hixson
<charleshixsn@earthlink.net> wrote:
> #    @note Instances can be created only from existing dicts.
>
>     ##    Class initializer.
>     #    @param    ddict    The data dictionary to which this is a read only
>     #            access.
>     #    @throws    TypeError if ddict is not a dict.
>     def __init__ (self, ddict = {}):
>         if not isinstance(ddict, dict):
>             raise    TypeError("ddict must be a dict.  It is " +
> repr(ddict))
>         self._ddict    =    ddict

Instead of demanding that a dict (or dict subclass) be passed, why not
simply pass all args on to dict() itself? Is there a reason this won't
work?

def __init__(self, *args, **kwargs):
    self._ddict = dict(*args, **kwargs)

ChrisA

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


Thread

Re: 1st Sketch at at ReadOnly dict Chris Angelico <rosuav@gmail.com> - 2014-01-21 11:08 +1100

csiph-web