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


Groups > comp.lang.python > #107739

Re: Differences between Class(Object) and Class(Dict) for dictionary usage?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Christopher Reimer <christopher_reimer@icloud.com>
Newsgroups comp.lang.python
Subject Re: Differences between Class(Object) and Class(Dict) for dictionary usage?
Date Wed, 27 Apr 2016 18:27:22 -0700
Lines 23
Message-ID <mailman.157.1461806845.32212.python-list@python.org> (permalink)
References <5720357B.4060009@icloud.com> <CALwzidn0SN5yax3bfmTPDTxBvfr+bnVNzeUe3dZYrS9ji2WCtw@mail.gmail.com> <572166FA.3020108@icloud.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de Zz8/30i34Mj+GSaB4TBvog//zgRxgMekHbSG+JUC/06g==
Return-Path <christopher_reimer@icloud.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'essentially': 0.04; 'attributes': 0.07; 'line:': 0.07; 'subject:Object': 0.09; 'subject: \n ': 0.15; 'distinction': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:between': 0.16; 'subject:usage': 0.16; 'wrote:': 0.16; 'am,': 0.23; 'examples': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'equivalent': 0.27; 'received:17': 0.27; 'looks': 0.29; 'regardless': 0.31; 'received:10.0.0': 0.32; 'subject:) ': 0.32; 'class': 0.33; 'definition': 0.34; 'received:10.0': 0.34; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'thank': 0.38; 'to:addr:python.org': 0.40; 'header:MIME- version:1': 0.60; 'charset:windows-1252': 0.62; 'inherit': 0.66; 'dict,': 0.84; 'dict.': 0.84; 'header:In-reply-to:1': 0.84; 'subject:Class': 0.91
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2016-04-27_14:,, signatures=0
X-Proofpoint-Spam-Details rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1510270003 definitions=main-1604280017
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
In-reply-to <CALwzidn0SN5yax3bfmTPDTxBvfr+bnVNzeUe3dZYrS9ji2WCtw@mail.gmail.com>
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=4d515a; t=1461806842; bh=1BwG8fclo55V6ijfB5XI1qk52XXNZdJQqCTcx+6Y7nU=; h=Subject:To:From:Message-id:Date:MIME-version:Content-type; b=FEZSv77nQtT5GLlrkDXEd15bnF6fQ9wWkVpjNi76x6b2r4hyK6K0/Wtapm8ptrQ8T r9zSCv1qNjTmeAHx5bBYvXVyFadNpkj1T77fUnuPi4K3jI4hJANlsSB8y1YS9xpM3i afoCkXWSSzzVq5bd+BRLqi5K+s+l7O1fnT3Cw27N1flxbSuHjdcyRSnmn5Emyl77k+ pls6G7pufAyht6mMAhUH8equ3sB27QBJes4CwMcIIZ16VUFJ/sni5cd/4sVNJNwgKa VGTv5wmIQi3MUMCii2OBUgxuiOpSaqr0iCEAFpEjiipS+hFKmPxt4PY8Y/oeygQzHr Ish4bD2zyy2aw==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <572166FA.3020108@icloud.com>
X-Mailman-Original-References <5720357B.4060009@icloud.com> <CALwzidn0SN5yax3bfmTPDTxBvfr+bnVNzeUe3dZYrS9ji2WCtw@mail.gmail.com>
Xref csiph.com comp.lang.python:107739

Show key headers only | View raw


On 4/27/2016 7:33 AM, Ian Kelly wrote:

> This class definition looks muddled. Because Test2 inherits from dict,
> the object referred to by "self" will be a dict, and self.__dict__ is
> actually a *different* dict, containing the attributes of self. The
> line:
>
>      self.__dict__ = {'key', 'value'}
>
> is essentially equivalent to:
>
>      self.key = value
>
> and will be regardless of whether you inherit from object or dict. If
> you find this distinction confusing, then I recommend not inheriting
> from dict.

Which expression is Pythonic? I've seen both used in various examples on 
the Internet.

Thank you,

Chris R.

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


Thread

Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Christopher Reimer <christopher_reimer@icloud.com> - 2016-04-27 18:27 -0700

csiph-web