Skip to content

Instantly share code, notes, and snippets.

@mattkohl
Created June 5, 2017 11:19
Show Gist options
  • Save mattkohl/12f8653fe41103e0eb1ad853701f934f to your computer and use it in GitHub Desktop.
Save mattkohl/12f8653fe41103e0eb1ad853701f934f to your computer and use it in GitHub Desktop.
Overloading __iter__
class MyClass:
def __init__(self, a, b, c):
self.value_1 = a
self.value_2 = b
self.value_3 = c
def __iter__(self):
""" enables dict(object) functionality """
yield "key1", self.value_1
yield "key2", self.value_2
yield "key3", self.value_3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment