Python dictionary to variable assignments based on key value to variable name
Posted
by Art
on Stack Overflow
See other posts from Stack Overflow
or by Art
Published on 2010-05-10T00:52:34Z
Indexed on
2010/05/10
0:58 UTC
Read the original article
Hit count: 296
Basically, I want to take a
Dictionary like { "a":"bar", "b":"blah", "c":"abc", "d":"nada" }
and use it to set variables (in an Object) which have the same name as a key in the dictionary.
class Foo(Object)
{
self.a = ""
self.b = ""
self.c = ""
}
So in the the end self.a = "bar", self.b = "blah", etc... (and key "d" is ignored)
Any ideas?
© Stack Overflow or respective owner