warg.data_structures.named_ordered_dictionary.NamedOrderedDictionary

class warg.data_structures.named_ordered_dictionary.NamedOrderedDictionary(*args: Any, **kwargs: Any)[source]

Bases: MutableMapping

Usage:


nodict = NamedOrderedDictionary() nodict.paramA = ‘str_parameter’ nodict.paramB = 10 assert nodict.paramA == ‘str_parameter’ assert nodict.paramB == 10


nodict = NamedOrderedDictionary() nodict[‘paramA’] = 10 assert nodict.paramA == 10


nodict = NamedOrderedDictionary({‘paramA’: ‘str_parameter’, ‘paramB’: 10}) assert nodict.paramA == ‘str_parameter’ assert nodict.paramB == 10


nodict = NamedOrderedDictionary(paramA=’str_parameter’, paramB=10) assert nodict.paramA == ‘str_parameter’ assert nodict.paramB == 10


nodict = NamedOrderedDictionary(‘str_parameter’, 10) assert nodict.arg0 == ‘str_parameter’ assert nodict.arg1 == 10


arg0,arg1 = NamedOrderedDictionary(‘str_parameter’, 10).as_list() assert arg0 == ‘str_parameter’ assert arg1 == 10

As with dictionaries you can use the update() method.


nodict = NamedOrderedDictionary() nodict.update({‘paramA’: 20, ‘paramB’: ‘other_param’, ‘paramC’: 5.0}) assert nodict.paramA == 20 assert nodict.paramB == ‘other_param’


nodict = NamedOrderedDictionary(‘str_parameter’, 10) nodict.update({‘arg1’: 20, ‘arg0’: ‘other_param’}) assert nodict.arg0 == ‘other_param’ assert nodict.arg1 == 20


nodict = NamedOrderedDictionary(paramA=’str_parameter’, paramB=10) nodict.update(20,’other_param’) assert nodict.paramB == ‘other_param’ assert nodict.paramA == 20

__init__(*args: Any, **kwargs: Any) None[source]

Methods

__init__(*args, **kwargs)

add_unnamed_arg(arg)

as_dict()

as_flat_tuples()

as_list()

as_tuples()

clear()

get(k[,d])

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[,d])

update(*args, **kwargs)

Merge two attributes, overriding any repeated keys from the items parameter.

values()

add_unnamed_arg(arg: Any) None[source]
Parameters:

arg

as_dict() dict[source]
Returns:

Return type:

as_flat_tuples() List[Tuple][source]
Returns:

Return type:

as_list() list[source]
Returns:

Return type:

as_tuples() List[Tuple[Any, Any]][source]
Returns:

Return type:

clear() None.  Remove all items from D.
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
items() ItemsView[source]
Returns:

Return type:

keys() KeysView[source]
Returns:

Return type:

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update(*args: Any, **kwargs: Any) T[source]

Merge two attributes, overriding any repeated keys from the items parameter.

:returns self

Args: items (dict): Python dictionary containing updated values.

values() ValuesView[source]
Returns:

Return type: