Skip to content

Instantly share code, notes, and snippets.

@davidnvq
Last active June 5, 2019 09:53
Show Gist options
  • Save davidnvq/dd6d5a35b8ff916c456523a30dbf304b to your computer and use it in GitHub Desktop.
Save davidnvq/dd6d5a35b8ff916c456523a30dbf304b to your computer and use it in GitHub Desktop.
Init class to get an instance with parameter dictionary
class Foo():
def __init__(self, a, b, c, d=0):
self.a = a
self.b = b
self.c = c
self.d = d
params = {
'b' : 2,
'c' : 3,
'a' : 1,
'd' : 4
}
foo = Foo(**params)
for var in foo.__dict__:
print(foo.__dict__[var])
# Out:
1
2
3
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment