MCPcopy Index your code
hub / github.com/python/cpython / config_dict

Function config_dict

Lib/turtle.py:168–195  ·  view source on GitHub ↗

Convert content of config-file into dictionary.

(filename)

Source from the content-addressed store, hash-verified

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

Callers 1

readconfigFunction · 0.85

Calls 5

openFunction · 0.70
readlinesMethod · 0.45
stripMethod · 0.45
startswithMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…