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 OOL[source]

Bases: meds.object.Object

find(txt=None)[source]
register(key, val)[source]
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)
clear()[source]
consume(value)[source]
grep(val)[source]
isSet()[source]
json(*args, **kwargs)[source]
load(path='', force=True)[source]
merge(obj)[source]
nice(*args, **kwargs)[source]
prepare()[source]
read(path)[source]
ready()[source]
register(key, val, force=False)[source]
save(stime='')[source]
search(name)[source]
sync(*args, **kwargs)
wait(sec=None)[source]