MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / config_dict

Function config_dict

tools/python-3.11.9-amd64/Lib/turtle.py:172–199  ·  view source on GitHub ↗

Convert content of config-file into dictionary.

(filename)

Source from the content-addressed store, hash-verified

170 }
171
172def config_dict(filename):
173 """Convert content of config-file into dictionary."""
174 with open(filename, "r") as f:
175 cfglines = f.readlines()
176 cfgdict = {}
177 for line in cfglines:
178 line = line.strip()
179 if not line or line.startswith("#"):
180 continue
181 try:
182 key, value = line.split("=")
183 except ValueError:
184 print("Bad line in config-file %s:\n%s" % (filename,line))
185 continue
186 key = key.strip()
187 value = value.strip()
188 if value in ["True", "False", "None", "''", '""']:
189 value = eval(value)
190 else:
191 try:
192 if "." in value:
193 value = float(value)
194 else:
195 value = int(value)
196 except ValueError:
197 pass # value need not be converted
198 cfgdict[key] = value
199 return cfgdict
200
201def readconfig(cfgdict):
202 """Read config-files, change configuration-dict accordingly.

Callers 1

readconfigFunction · 0.85

Calls 6

stripMethod · 0.80
startswithMethod · 0.80
openFunction · 0.70
printFunction · 0.50
readlinesMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected