Differences between Class(Object) and Class(Dict) for dictionary usage?
Christopher Reimer
christopher_reimer at icloud.com
Tue Apr 26 23:43:55 EDT 2016
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.
More information about the Python-list
mailing list