File size: 634 Bytes
c3c0d39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import datetime
import re


def str_to_date(str_date):
    return datetime.datetime.strptime(str_date, "%d/%m/%Y").date()


def str_to_list(value, separators=',;\n'):
    """
    Tries to translate a string of separated values into a list of strings.
    The separators are commas and carriage returns.

    In case the string does not seem to represent a list of values, a warning is logged and an empty list is returned.
    """
    if not isinstance(value, str):
        raise TypeError
    if value == '':
        return []
    return list(filter(lambda x: x != '', map(lambda x: x.strip(), re.split('['+separators+']', value))))