cobra.util.util

General utilities used across the package.

Module Contents

Classes

AutoVivification

Implementation of Perl's autovivification feature.

Functions

format_long_string(→ 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__(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.