Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107705 > unrolled thread
| Started by | Random832 <random832@fastmail.com> |
|---|---|
| First post | 2016-04-26 23:56 -0400 |
| Last post | 2016-04-26 23:56 -0400 |
| 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.
Re: Differences between Class(Object) and Class(Dict) for dictionary usage? Random832 <random832@fastmail.com> - 2016-04-26 23:56 -0400
| From | Random832 <random832@fastmail.com> |
|---|---|
| Date | 2016-04-26 23:56 -0400 |
| Subject | Re: Differences between Class(Object) and Class(Dict) for dictionary usage? |
| Message-ID | <mailman.140.1461729362.32212.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web