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))))