diff options
Diffstat (limited to 'src/argaze/DataStructures.py')
-rw-r--r-- | src/argaze/DataStructures.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/argaze/DataStructures.py b/src/argaze/DataStructures.py index 5648c0e..abaea62 100644 --- a/src/argaze/DataStructures.py +++ b/src/argaze/DataStructures.py @@ -6,7 +6,7 @@ import json class DictObject(): """Convert dictionnary into object""" - def __init__(self, object_type, **dictionnary): + def __init__(self, object_type = str, **dictionnary): self.__dict__.update(dictionnary) self.__type = object_type @@ -15,9 +15,9 @@ class DictObject(): return self.__dict__[key] def __str__(self): - return json.dumps({key: self.__dict__[key] for key in self.__dict__.keys()}, default=vars) + return json.dumps({key: self.__dict__[key] for key in self.__dict__.keys()}, default = vars) - def type(self): + def get_type(self): return self.__type def keys(self): @@ -51,8 +51,16 @@ class TimeStampedBuffer(collections.OrderedDict): super().__setitem__(key, value) def __str__(self): - return json.dumps(self, default=vars) + return json.dumps(self, default = vars) def pop_first(self): """Easing FIFO access mode""" - return self.popitem(last=False)
\ No newline at end of file + return self.popitem(last=False) + + def export_as_json(self, filepath): + """Write buffer content into a json file""" + try: + with open(filepath, 'w', encoding='utf-8') as jsonfile: + json.dump(self, jsonfile, ensure_ascii = False, default=vars) + except: + raise RuntimeError(f'Can\' write {filepath}')
\ No newline at end of file |