Skip to content

Instantly share code, notes, and snippets.

@toori67
Created March 25, 2017 17:58
Show Gist options
  • Save toori67/dc42b541a22aaf8b18f5ef5dcf999421 to your computer and use it in GitHub Desktop.
Save toori67/dc42b541a22aaf8b18f5ef5dcf999421 to your computer and use it in GitHub Desktop.
Simple class to dict
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