SEPIO

Author

Marcel Simader

Date

01.04.2021

New in version v0.1.0.

Console Arguments

exception SEPModules.SEPIO.ConsoleArgsError(msg, arguments)

Error class used to catch exceptions while parsing the sys.argv input for ConsoleManager.

class SEPModules.SEPIO.ConsoleArguments(argnames, kwargnames, *, no_load=False)

A console arguments manager that holds information about and offers API functionality for the console options and flags passed into the program. It immediately tries to read from sys.argv if the no_load option is not set upon creation of an instance.

Parameters
  • argnames (Iterable[str]) – a list of single-letter strings defining the options, adding : to the end of a letter indicates that a value must be passed to this flag

  • kwargnames (Iterable[str]) – a list of multi-letter string defining long options, adding = to the end of a string indicates that a value must be passed to this flag

  • no_load (bool) – keyword-only argument, prohibits the console manager from automatically reading sys.argv upon creation of the console arguments manager object

Raises
  • ValueError – if any option or long option share the same name

  • ConsoleArgsError – if there was an error while parsing the sys.argv input

Size properties of ConsoleArguments:

set_total, set_args, set_kwargs, set_pars, required

property set_total: int

See other size_dict properties:

Returns

the amount of set args, keyword args, and parameters.

property set_args: int

See other size_dict properties:

Returns

the amount of set args.

property set_kwargs: int

See other size_dict properties:

Returns

the amount of set keyword args.

property set_pars: int

See other size_dict properties:

Returns

the amount of set parameters.

property required: int

See other size_dict properties:

Returns

the amount of required args (e.g. a flag a:).

_load_arguments()

Load all arguments defined by the passed arg and kwarg names into ConsoleArguments by reading from sys.argv.

Raises

ConsoleArgsError – if there was an error while parsing

__contains__(options, *, _all=True)
Parameters

_all (bool) – can be set to True for checking against all values of type(options) == list/set or to False for only checking if any match

Returns

True if the options is found in args or kwargs.

Return type

bool

__getitem__(key)

Returns an argument/keyword argument if the supplied key is a str object. If the supplied key is of type int, the corresponding parameter is returned.

__iter__()

Iterate over args, then kwargs, and finally enumerate all pars entries.