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


Groups > comp.lang.python > #64382 > unrolled thread

Re: 1st Sketch at at ReadOnly dict

Started byChris Angelico <rosuav@gmail.com>
First post2014-01-21 11:08 +1100
Last post2014-01-21 11:08 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#64382 — Re: 1st Sketch at at ReadOnly dict

FromChris Angelico <rosuav@gmail.com>
Date2014-01-21 11:08 +1100
SubjectRe: 1st Sketch at at ReadOnly dict
Message-ID<mailman.5765.1390262921.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web