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


Groups > comp.lang.python > #107703

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

From Christopher Reimer <christopher_reimer@icloud.com>
Newsgroups comp.lang.python
Subject Differences between Class(Object) and Class(Dict) for dictionary usage?
Date 2016-04-26 20:43 -0700
Message-ID <mailman.138.1461728646.32212.python-list@python.org> (permalink)
References <5720357B.4060009@icloud.com>

Show all headers | View raw


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.

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


Thread

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

csiph-web