Created
October 30, 2015 19:43
-
-
Save ankona/5e25cb17bca334efe7fa to your computer and use it in GitHub Desktop.
Copy properties from one python object to another
This file contains 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
def __copy_properties(copy_from, copy_to): | |
for key in copy_from: | |
print 'found ' + str(key) | |
if hasattr(copy_to, key): | |
print 'for key "{2}" - copying value "{0}" from copy_from and replacing value "{1}" in copy_to'.format(copy_from[key], getattr(copy_to, key), key) | |
setattr(copy_to, key, copy_from[key]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment