cosapp.utils.parsing¶
Functions
|
Decompose a string expression into basename and selector, where selector is a suitable mask expression for an array. |
|
Reciprocal of multi_split. |
|
Extension of str.split, accounting for more than one split separators. |
- cosapp.utils.parsing.find_selector(expression: str) Tuple[str, str][source]¶
Decompose a string expression into basename and selector, where selector is a suitable mask expression for an array.
Parameters:¶
expression [str]: the expression to be parsed.
Returns:¶
baseline, selector [str, str]
- cosapp.utils.parsing.multi_join(expressions: List[str], separators: List[str], add_space=False) str[source]¶
Reciprocal of multi_split.
Parameters:¶
- expressions [list[str]]:
Expression to be split.
- separators [list[str]]:
List of separators.
Returns:¶
- expression [str]:
Joined expression.
Examples:¶
>>> multi_join(['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+']) 'a+b-c-d+e' >>> multi_join(['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+'], add_space=True) 'a + b - c - d + e'
- cosapp.utils.parsing.multi_split(expression: str, separators: Collection[str]) Tuple[List[str], List[str]][source]¶
Extension of str.split, accounting for more than one split separators.
Parameters:¶
- expression [str]:
Expression to be split.
- separators [collection[str]]:
List/tuple/set of separators.
Returns:¶
- expressions [list[str]]:
List of n split expressions.
- separators [list[str]]:
Sequence of (n - 1) separators between split expressions.
Examples:¶
>>> multi_split('a+b-c-d+e', list('+-')) ['a', 'b', 'c', 'd', 'e'], ['+', '-', '-', '+']