dictobj#

class dictobj(*args, **kwargs)[source]#

Bases: dict

Lightweight class to create an object that can also act like a dictionary.

Example:

obj = sc.dictobj()
obj.a = 5
obj['b'] = 10
print(obj.items())

For a more powerful alternative, see sc.objdict().

Note: because dictobj is halfway between a dict and an object, it can’t be automatically converted to a JSON (but will fail silently). Use to_json() instead.

New in version 1.3.0.
New in version 1.3.1: inherit from dict
New in version 2.0.0: allow positional arguments
New in version 3.0.0: “fromkeys” now a class method; to_json() method
New in version 3.1.6: “copy” returns another dictobj

Methods

to_json()[source]#

Export the dictobj to JSON (NB: regular json.dumps() does not work)

classmethod fromkeys(*args, **kwargs)[source]#

Create a new dictobj from keys

copy()[source]#

Create a shallow copy

clear() None.  Remove all items from D.[source]#
get(*args, **kwargs)[source]#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items[source]#
keys() a set-like object providing a view on D's keys[source]#
pop(k[, d]) v, remove specified key and return the corresponding value.[source]#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem(*args, **kwargs)[source]#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(*args, **kwargs)[source]#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from dict/iterable E and F.[source]#

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values[source]#