datasus_db.utils

Module with generic helper functions

 1"""Module with generic helper functions"""
 2
 3import itertools
 4import os
 5
 6
 7def format_year(year, digits=2):
 8    if isinstance(year, str) and not year.isnumeric():
 9        return "*"
10
11    year = str(year).zfill(digits)
12
13    return year[-digits:]
14
15
16def format_month(month):
17    if isinstance(month, str) and not month.isnumeric():
18        return "*"
19
20    return str(month).zfill(2)
21
22
23def flatten(list_of_lists):
24    return itertools.chain.from_iterable(list_of_lists)
25
26
27def rm(file: str):
28    if os.path.exists(file):
29        os.remove(file)
def format_year(year, digits=2):
 8def format_year(year, digits=2):
 9    if isinstance(year, str) and not year.isnumeric():
10        return "*"
11
12    year = str(year).zfill(digits)
13
14    return year[-digits:]
def format_month(month):
17def format_month(month):
18    if isinstance(month, str) and not month.isnumeric():
19        return "*"
20
21    return str(month).zfill(2)
def flatten(list_of_lists):
24def flatten(list_of_lists):
25    return itertools.chain.from_iterable(list_of_lists)
def rm(file: str):
28def rm(file: str):
29    if os.path.exists(file):
30        os.remove(file)