Skip to content

Commit 4a9f129

Browse files
committed
Adds a simple AttributeDict class which impliments __getattr__ and __setattr__ methods to allow for general dict usage in a JSON object fashion while retaining dict class flexibility
1 parent d6baffa commit 4a9f129

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

sc2reader/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,16 @@ def key_in_bases(key,bases):
487487
if key in clazz.__dict__: return True
488488
return False
489489

490+
class AttributeDict(dict):
491+
def __getattr__(self, name):
492+
try:
493+
return self[name]
494+
except KeyError:
495+
raise AttributeError('No such attribute {0}'.format(name))
496+
497+
def __setattr__(self, name, value):
498+
self[name] = value
499+
490500
def read_header(file):
491501
''' Read the file as a byte stream according to the documentation found at:
492502
http://wiki.devklog.net/index.php?title=The_MoPaQ_Archive_Format

0 commit comments

Comments
 (0)