I have a dict of configuration variables that looks something like this:
self.config = {
"foo": "abcdef",
"bar": 42,
"xyz": True
}
I want to be able to update these variables from user input (which, in this case, will always be in the form of a string). The problem I'm facing is obvious, and my first solution seemed good enough to me:
def updateconfig(self, key, value):
if key in self.config:
self.config[key] = type(self.config[key])(value)
However, #python in Freenode almost seemed offended that I would suggest such a solution. Could someone tell me why this is bad practice?