Created
March 25, 2017 17:58
-
-
Save toori67/dc42b541a22aaf8b18f5ef5dcf999421 to your computer and use it in GitHub Desktop.
Simple class to dict
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
class Foo: | |
def __init__(self): | |
self.a = 10 | |
self.b = 'simple' | |
def to_dict(obj): | |
return obj.__dict__ | |
def to_dict2(obj): | |
d = {} | |
for k,v in obj.__dict__.item(): | |
if key.startswith('_'): | |
continue | |
d[k] = v | |
return d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment