meds.object¶
An Object adds ‘dotted access’ to dicts to allow for better readable code. Object’s also allow for saving JSON to disk to allow it to be restored at a later time.
Exceptions
EBORDER |
|
EISMETHOD |
Attribute is a method. |
ENOJSON |
|
ENOTSET |
|
ESET |
Attribute is already set. |
ESIGNATURE |
-
class
Object
[source]¶ Bases:
dict
Core Object of the MEDS bot, provides saving to JSON files, using timestamps in the filename so collections of object in a period of time is possible.
constructing an Object:
>>> obj = Object() >>> print(obj) {}
setting attributes on an Object:
>>> obj.key1 = "value1" >>> obj["key2"] = "value2"
accessing attributes can also be ‘dotted’ or with a dict key:
>>> v1 = obj.key1 >>> v2 = obj["key2"]
saving is easy, the save() method will use the current time as timestamp:
>>> path = obj.save()
syncing to an already saved file is done with the sync() method:
>>> path = obj.sync()
the json() method can be used to get a JSON string of the object:
>>> s = obj.json()
nice() will give you a more readable presentation:
>>> s = obj.nice()
use the load() method to read a file into an Object:
>>> path = obj._path >>> test = Object() >>> obj = test.load(path)
-
sync
(*args, **kwargs)¶
-