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


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

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

Started byChristopher Reimer <christopher_reimer@icloud.com>
First post2016-04-26 20:43 -0700
Last post2016-04-26 20:43 -0700
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

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

#107703 — Differences between Class(Object) and Class(Dict) for dictionary usage?

FromChristopher Reimer <christopher_reimer@icloud.com>
Date2016-04-26 20:43 -0700
SubjectDifferences between Class(Object) and Class(Dict) for dictionary usage?
Message-ID<mailman.138.1461728646.32212.python-list@python.org>
Greetings,

If I'm using a dictionary to store variables for an object, and 
accessing the variable values from dictionary via property decorators, 
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.

Thank you,

Chris R.

[toc] | [standalone]


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


csiph-web