Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107705
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Random832 <random832@fastmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Differences between Class(Object) and Class(Dict) for dictionary usage? |
| Date | Tue, 26 Apr 2016 23:56:00 -0400 |
| Lines | 30 |
| Message-ID | <mailman.140.1461729362.32212.python-list@python.org> (permalink) |
| References | <5720357B.4060009@icloud.com> <1461729360.3276080.590752673.7A6E1041@webmail.messagingengine.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de JByQCYzqqEyQDljq40XTHQxJYB3btjhvOjpBoWnmLtag== |
| Return-Path | <random832@fastmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'attributes': 0.07; 'dict': 0.09; 'received:internal': 0.09; 'subject:Object': 0.09; 'def': 0.13; 'subject: \n ': 0.15; 'variables': 0.15; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.212': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'self)': 0.16; 'subject:between': 0.16; 'subject:usage': 0.16; 'wrote:': 0.16; 'variable': 0.18; 'otherwise,': 0.20; 'code.': 0.23; 'seems': 0.23; "haven't": 0.24; 'header:In-Reply- To:1': 0.24; 'discussion': 0.24; "doesn't": 0.26; 'object,': 0.27; 'values': 0.28; 'dictionary': 0.29; "i'm": 0.30; 'skip:_ 10': 0.32; 'subject:) ': 0.32; 'point': 0.33; 'class': 0.33; 'tue,': 0.34; 'sometimes': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'seem': 0.37; '(with': 0.38; 'difference': 0.38; 'received:66': 0.38; 'mean': 0.38; 'rather': 0.39; 'to:addr:python.org': 0.40; 'header:Message- Id:1': 0.61; 'greetings,': 0.61; 'great': 0.63; 'other.': 0.64; 'benefit': 0.66; 'internet': 0.70; '26,': 0.72; 'dict.': 0.84; 'or:': 0.84; 'approach.': 0.91; 'played': 0.91; 'subject:Class': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=p567FGzRK6xfb2m/fItZ2xO6UJU=; b=X9Ct1/ Mp0vPitNKX/L1BePDq4H3nv9SI2cDUsv0t4sFr+8cg+9JrSX9jDzY/jCz9iLV635 JjCFOodHps5VIUQLo+LfXhrRZmc7i0RT5ylZ5rui/gPXfXburWYpvFLcW0kwkRxz ZCXc30ucnYt7LRg5mUxMyaij7Hs1hKPqUP4Yw= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=p567FGzRK6xfb2m /fItZ2xO6UJU=; b=m6gYKlweUt5r4eT2Ax/d77a9/W8KXs0CShSSU5KYRRrOjGi oiFnIevItWay5N6e6bgknwpGxlt8Bew/ZpSZAqmcCABjmfqqnWic4p24lUQn6iHl MfC9uHCXDVyOtICXGzoPMGo6J8P6n95qlwsKwEqSDHcdNd6mqVGug/P9kOi0= |
| X-Sasl-Enc | qBP8X4QL5hfPJHujeVmyPFP+5j/i6YDrIwNOJb8bWh90 1461729360 |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-b462e126 |
| In-Reply-To | <5720357B.4060009@icloud.com> |
| 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 | <1461729360.3276080.590752673.7A6E1041@webmail.messagingengine.com> |
| X-Mailman-Original-References | <5720357B.4060009@icloud.com> |
| Xref | csiph.com comp.lang.python:107705 |
Show key headers only | View raw
On Tue, Apr 26, 2016, at 23:43, Christopher Reimer wrote:
> Greetings,
>
> If I'm using a dictionary to store variables for an object, and
> accessing the variable values from dictionary via property decorators,
what exactly do you mean by property decorators? If you're just
accessing them in a dictionary what's the benefit over having the values
be simple attributes rather than properties?
> would it be better to derive the class from object or dict?
>
> class Test1(object):
> def __init__(self):
> self.state = {'key': 'value'}
>
> Or:
>
> class Test2(dict):
> def __init__(self):
> self.__dict__ = {'key', 'value'}
>
> I haven't seen a good pro/con discussion on the Internet for using one
> over the other. I played with both in my code. Doesn't seem to make a
> great difference either way. Using object seems to be the most simplest
> approach.
I sometimes use dict (with self.__dict__ = self) if I want to be able to
access values via either obj['key'] or obj.key (a la Javascript).
Otherwise, there's no point in using dict.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Random832 <random832@fastmail.com> - 2016-04-26 23:56 -0400
csiph-web