Skip to content

Instantly share code, notes, and snippets.

@ankona
Created October 30, 2015 19:43
Show Gist options
  • Save ankona/5e25cb17bca334efe7fa to your computer and use it in GitHub Desktop.
Save ankona/5e25cb17bca334efe7fa to your computer and use it in GitHub Desktop.
Copy properties from one python object to another
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