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). Useto_json()
instead.New in version 1.3.0.New in version 1.3.1: inherit from dictNew in version 2.0.0: allow positional argumentsNew in version 3.0.0: “fromkeys” now a class method;to_json()
methodNew in version 3.1.6: “copy” returns another dictobjMethods
- to_json()[source]#
Export the dictobj to JSON (NB: regular
json.dumps()
does not work)
- 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.