Last active
June 5, 2019 09:53
-
-
Save davidnvq/dd6d5a35b8ff916c456523a30dbf304b to your computer and use it in GitHub Desktop.
Init class to get an instance with parameter dictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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