@@ -4,24 +4,17 @@ def write_converted_ini_cst(parsed_portion, output_folder_path):
4
4
if isinstance (dict_or_list , dict ): # If dict_or_list contains a dictionary of more filenames.
5
5
write_converted_ini_cst (dict_or_list , output_folder_path / name )
6
6
else : # If dict_or_list contains a list of the sections of a file.
7
- # pprint.pprint(dict_or_list)
8
7
with open (str (output_folder_path / name ), mode = "w" ) as f :
9
8
lines = []
10
9
for section in dict_or_list :
11
- get_lines_from_dicts_recursively (section , lines )
12
- f .write ("\n " .join (lines ))
10
+ write_recursively (section , lines )
11
+ f .write ("" .join (lines ))
13
12
14
13
15
- def get_lines_from_dicts_recursively (line_tokens , lines ):
16
- # This function loops twice through line_tokens so the lines can be appended in the correct order.
17
-
18
- line = ""
19
- for dictionary in line_tokens :
20
- if dictionary ["type" ] != "children" :
21
- line += dictionary ["content" ]
22
- lines .append (line )
23
-
24
- for dictionary in line_tokens :
25
- if dictionary ["type" ] == "children" :
26
- for line_tokens in dictionary ["content" ]:
27
- get_lines_from_dicts_recursively (line_tokens , lines )
14
+ def write_recursively (line_tokens , lines ):
15
+ for token in line_tokens :
16
+ if token ["type" ] != "children" :
17
+ lines .append (token ["content" ])
18
+ elif token ["type" ] == "children" :
19
+ for line_tokens in token ["content" ]:
20
+ write_recursively (line_tokens , lines )
0 commit comments