ObjDict¶
-
class
utilipy.utils.
ObjDict
(name: str = '', **kw: Any)[source]¶ Bases:
collections.OrderedDict
Dictionary-like object intended to store information.
instantiated with a name (str) supports __getattr__ as a redirect to __getitem__.
- Parameters
- name: str
the name of the object
- **kw
items for ObjDict
Examples
>>> obj = ObjDict('NAME', a=1, b=2) >>> print(obj.name, obj.a, obj['b']) NAME 1 2
Initialize ObjDict.
Methods Summary
dump
(fname[, protocol, fopt, fix_imports])Dump to pickle file.
fromkeys
([keys, name])Subset.
getitem
(keys[, as_generator])Override __getitem__.
items
(*keys)Items.
keyslist
()Keys in list form.
load
(fname, *[, fopt, fix_imports, …])Load from pickle file.
print
()Print.
save
(fname[, protocol, fopt, fix_imports])Dump to pickle file.
values
(*keys)Values.
Methods Documentation
-
dump
(fname: str, protocol: Optional[int] = None, *, fopt: str = 'b', fix_imports: bool = True)[source]¶ Dump to pickle file.
uses
dump()
-
fromkeys
(keys: Any = [], name: Optional[str] = None) → Any[source]¶ Subset.
- Parameters
- *keys: keys for subset dictionary, default is all keys
- Returns
- subset: list
items for
*keys
-
getitem
(keys: Union[str, Sequence[str]], as_generator: bool = False) → Any[source]¶ Override __getitem__.
- Parameters
- keys: str, list of str
the keys into ObjDict if str: just the value from key-value pair if list: list of values
- as_generator: bool (default False)
whether to return as a generator only if keys is a list
- Returns
- value(s): anything
if str, just the value from key-value pair if list, list of values if as_generator, generator for list
Examples
obj = ObjDict(‘NAME’, a=1, b=2) print(obj[‘a’]) >> 1, [NAME, 2] print(obj[‘name’, ‘b’]) >> [NAME, 2]
-
items
(*keys: Any) → Union[odict_items, dict][source]¶ Items.
- Parameters
- *keys: keys for items subset, default is all keys
- Returns
- items: dictionary
items for
*keys
-
keyslist
() → list[source]¶ Keys in list form.
- Parameters
- *keys: keys for subset dictionary, default is all keys
- Returns
- subset: list
items for
*keys
-
static
load
(fname: str, *, fopt: str = 'b', fix_imports: bool = True, encoding: str = 'ASCII', errors: str = 'strict')[source]¶ Load from pickle file.
uses
load()