17.1.1.8.1.5. cobra.util.util

General utilities used across the package.

17.1.1.8.1.5.1. Module Contents

17.1.1.8.1.5.1.1. Classes

AutoVivification

Implementation of Perl’s autovivification feature.

17.1.1.8.1.5.1.2. Functions

format_long_string(string: str, max_length: int = 50) → str

Shorten long string into a small string with ellipsis.

show_versions() → None

Print dependency information.

cobra.util.util.format_long_string(string: str, max_length: int = 50) → str[source]

Shorten long string into a small string with ellipsis.

Parameters
  • string (str) – The long string to shorten.

  • max_length (int, optional) – The maximum length after which to append ellipsis (default 50).

Returns

The shortened string.

Return type

str

class cobra.util.util.AutoVivification[source]

Bases: dict

Implementation of Perl’s autovivification feature.

Notes

For more information, check https://stackoverflow.com/a/652284/280182 .

__getitem__(self, item: Any) → Any[source]

Retrieve if item is found, else add it.

Parameters

item (Any) – The object to look for.

Returns

The retrieved object.

Return type

Any

cobra.util.util.show_versions() → None[source]

Print dependency information.