File size: 753 Bytes
67d041f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from argparse import Namespace

def Recursive_Parse(args_dict):
    parsed_dict = {}
    for key, value in args_dict.items():
        if isinstance(value, dict):
            value = Recursive_Parse(value)
        parsed_dict[key]= value

    args = Namespace()
    args.__dict__ = parsed_dict
    return args

def To_Non_Recursive_Dict(
    args: Namespace
    ):
    parsed_dict = {}
    for key, value in args.__dict__.items():
        if isinstance(value, Namespace):
            value_dict = To_Non_Recursive_Dict(value)
            for sub_key, sub_value in value_dict.items():
                parsed_dict[f'{key}.{sub_key}'] = sub_value
        else:
            parsed_dict[key] = value

    return parsed_dict