ConfigReader

class negmas.helpers.ConfigReader[source]

Bases: object

Methods Summary

from_config(config[, section, …])

Creates an object of this class given the configuration info

read_config(config[, section])

Reads the configuration from a file or a dict and prepares it for parsing

Methods Documentation

classmethod from_config(config: Union[str, dict], section: Optional[str] = None, ignore_children: bool = True, try_parsing_children: bool = True, scope=None)[source]

Creates an object of this class given the configuration info

Parameters
  • config – Either a file name or a dictionary

  • section – A section in the file or a key in the dictionary to use for loading params

  • ignore_children – If true then children will be ignored and there will be a single return

  • try_parsing_children – If true the children will first be parsed as ConfigReader classes if they are not

  • types (e.g. int (simple) –

  • str

  • float

  • Iterable[int|str|float]

  • scope – The scope at which to evaluate any child classes. This MUST be passed as scope=globals() if you are

  • any children that are to be parsed. (having) –

Returns

An object of cls if ignore_children is True or a tuple with an object of cls and a dictionary with children that were not parsed.

Remarks:

  • This function will return an object of its class after passing the key-value pairs found in the config to the init function.

  • Requiring passing scope=globals() to this function is to get around the fact that in python eval() will be called with a globals dictionary based on the module in which the function is defined not called. This means that in general when eval() is called to create the children, it will not have access to the class definitions of these children (except if they happen to be imported in this file). To avoid this problem causing an undefined_name exception, the caller must pass her globals() as the scope.

classmethod read_config(config: Union[str, dict], section: Optional[str] = None)Dict[str, Any][source]

Reads the configuration from a file or a dict and prepares it for parsing

Parameters
  • config – Either a file name or a dictionary

  • section – A section in the file or a key in the dictionary to use for loading params

Returns

A dict ready to be parsed by from_config

Remarks: