olivia_finder.utilities.utilities

 1import os
 2
 3
 4def clean_string(string: str):
 5    '''
 6    Clean a string from whitespaces and newlines
 7
 8    Parameters
 9    ----------
10    string : str
11        String to be cleaned
12
13    Returns
14    -------
15    str
16        Cleaned string
17
18    Examples
19    --------
20    >>> Util.clean_string("Hello world")
21    'Hello world'
22    >>> Util.clean_string("Hello world\\n")
23    'Hello world'
24    >>> Util.clean_string("Hello   world\\n\\n")
25    'Hello world'
26    '''
27    string = string.strip()
28    string = string.replace("\r", "")
29    string = string.replace("\t", "")
30    string = string.replace("\n", "")
31    return string.replace("  ", " ")
32
33def setup_path(path: str) -> None:
34    '''
35    Setup a path, creating the directory if it does not exist
36
37    Parameters
38    ----------
39    path : str
40        Path to be setup
41
42    Returns
43    -------
44    str
45        Setup path
46
47    Examples
48    --------
49    >>> Util.setup_path("test")
50    'test'
51    '''
52
53    file_name = os.path.basename(path)
54    path = path.replace(file_name, "")
55
56    if not os.path.exists(path) and path != "":
57        os.makedirs(path)
def clean_string(string: str):
 5def clean_string(string: str):
 6    '''
 7    Clean a string from whitespaces and newlines
 8
 9    Parameters
10    ----------
11    string : str
12        String to be cleaned
13
14    Returns
15    -------
16    str
17        Cleaned string
18
19    Examples
20    --------
21    >>> Util.clean_string("Hello world")
22    'Hello world'
23    >>> Util.clean_string("Hello world\\n")
24    'Hello world'
25    >>> Util.clean_string("Hello   world\\n\\n")
26    'Hello world'
27    '''
28    string = string.strip()
29    string = string.replace("\r", "")
30    string = string.replace("\t", "")
31    string = string.replace("\n", "")
32    return string.replace("  ", " ")

Clean a string from whitespaces and newlines

Parameters
  • string (str): String to be cleaned
Returns
  • str: Cleaned string
Examples
>>> Util.clean_string("Hello world")
'Hello world'
>>> Util.clean_string("Hello world\n")
'Hello world'
>>> Util.clean_string("Hello   world\n\n")
'Hello world'
def setup_path(path: str) -> None:
34def setup_path(path: str) -> None:
35    '''
36    Setup a path, creating the directory if it does not exist
37
38    Parameters
39    ----------
40    path : str
41        Path to be setup
42
43    Returns
44    -------
45    str
46        Setup path
47
48    Examples
49    --------
50    >>> Util.setup_path("test")
51    'test'
52    '''
53
54    file_name = os.path.basename(path)
55    path = path.replace(file_name, "")
56
57    if not os.path.exists(path) and path != "":
58        os.makedirs(path)

Setup a path, creating the directory if it does not exist

Parameters
  • path (str): Path to be setup
Returns
  • str: Setup path
Examples
>>> Util.setup_path("test")
'test'