Created
October 5, 2018 18:25
-
-
Save ardenn/76aa5653245388519a2edb690d8ed7ba 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
def convert_to_dict(obj): | |
""" | |
A function takes in a custom object and returns a dictionary representation of the object. | |
This dict representation includes meta data such as the object's module and class names. | |
""" | |
# Populate the dictionary with object meta data | |
obj_dict = { | |
"__class__": obj.__class__.__name__, | |
"__module__": obj.__module__ | |
} | |
# Populate the dictionary with object properties | |
obj_dict.update(obj.__dict__) | |
return obj_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment