Last active
October 28, 2016 07:43
-
-
Save qgp9/c00c53137c8c7da7ea4628235218cd87 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python3 | |
def load_on_default( obj, pargs ): | |
for k, v in pargs.items(): | |
if( hasattr( obj, k ) ): | |
setattr(obj, k, v ) | |
else: | |
print( "WARNING: the key \"{}\" is wrong.".format(k) ) | |
class MyClass: | |
def __init__(self,**pargs): | |
self.a = 1 | |
self.b = 2 | |
load_on_default(self,pargs) | |
myobj = MyClass(a=2,b=3) | |
print( 'a={}\tb={}'.format(myobj.a,myobj.b) ) | |
myobj = MyClass(a=4,d=5) | |
print( 'a={}\tb={}'.format(myobj.a,myobj.b) ) |
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
a=2 b=3 | |
WARNING: the key "d" is wrong. | |
a=4 b=2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment