Skip to content

str

Collection of string related functions

Functions

contains

contains(text: str, *args) -> bool

Check if text contains all given substrings.

Parameters:

  • text

    (str) –

    Text to analyse.

  • args

    (list[str], default: () ) –

    List of substrings to match.

Returns:

  • bool ( bool ) –

    True if all substrings are found in the text.

Source code in ipsl_common/str.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
def contains(text: str, *args) -> bool:
    """Check if text contains all given substrings.

    Args:
        text (str): Text to analyse.
        args (list[str]): List of substrings to match.

    Returns:
        bool: True if all substrings are found in the text.
    """
    for arg in args:
        if text not in arg:
            return False
    return True

contains_any

contains_any(text: str, *args) -> bool

Check if text contains any of given substrings.

Parameters:

  • text

    (str) –

    Text to analyse.

  • args

    (list[str], default: () ) –

    List of substrings to match.

Returns:

  • bool ( bool ) –

    True if any of substrings is found in the text.

Source code in ipsl_common/str.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def contains_any(text: str, *args) -> bool:
    """Check if text contains any of given substrings.

    Args:
        text (str): Text to analyse.
        args (list[str]): List of substrings to match.

    Returns:
        bool: True if any of substrings is found in the text.
    """
    for arg in args:
        if text in arg:
            return True
    return False

is_float

is_float(text: str) -> bool

Check if text represents floating value.

Parameters:

  • text

    (str) –

    Text to verify

Returns:

  • bool ( bool ) –

    True if text represents a floating value.

Source code in ipsl_common/str.py
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def is_float(text: str) -> bool:
    """Check if text represents floating value.

    Args:
        text(str): Text to verify

    Returns:
        bool: True if text represents a floating value.
    """
    try:
        float(text)
    except ValueError:
        return False
    else:
        return True

is_int

is_int(text: str) -> bool

Check if text represents integer value.

Parameters:

  • text

    (str) –

    Text to verify

Returns:

  • bool ( bool ) –

    True if text represents an integer value.

Source code in ipsl_common/str.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def is_int(text: str) -> bool:
    """Check if text represents integer value.

    Args:
        text(str): Text to verify

    Returns:
        bool: True if text represents an integer value.
    """
    try:
        int(text)
    except ValueError:
        return False
    else:
        return True