String operations

This module contains operations commonly used in image processing.

morphocut.str.Format()[source]

Format strings using str.format().

For more information see the Python Format String Syntax.

Parameters
  • fmt (str or Variable[str]) – A format in which we want our string to be.

  • *args (Any or Variable[Any]) – Positional arguments for positional fields in fmt.

  • _args (Sequence or Variable[Sequence]) – Additional positional arguments for positional fields in fmt.

  • _kwargs (Mapping or Variable[Mapping]) – Keyword arguments for named fields in fmt.

  • **kwargs (Any or Variable[Any]) – Additional keyword arguments for named fields in fmt.

As positional arguments, str.format() receives args then _args. As keyword arguments, str.format() receives _kwargs then kwargs. This means that keys passed as keyword arguments overwrite keys in a dict passed as _kwargs.

Example

fmt = "{},{},{},{},{},{},{a},{b},{c},{d}"
args = (1, 2, 3)
_args = (4, 5, 6)
_kwargs = {"a": 7, "b": 8}
kwargs = {"c": 9, "d": 10}

with Pipeline() as pipeline:
    result = Format(fmt, *args, _args=_args, _kwargs=_kwargs, **kwargs)

Result: obj[result] == “1,2,3,4,5,6,7,8,9,10” for a stream object obj.

morphocut.str.Parse()[source]

Parse information from a string.

Parse strings using a specification based on the Python Format String Syntax.

Note

The external dependency parse is required to use this Node.

Parameters
  • fmt (str) – The pattern to look for in the input.

  • string (str) – A string input which is to be parsed

  • case_sensitive (bool) – Match pattern with case.

Example

fmt = "This is a {named}"
string = "This is a TEST"
case_sensitive = True

with Pipeline() as pipeline:
    result = Parse(fmt, string, case_sensitive)

Result: obj[result] == {'named': 'TEST'} for a stream object obj.