Created
June 5, 2017 11:19
-
-
Save mattkohl/12f8653fe41103e0eb1ad853701f934f to your computer and use it in GitHub Desktop.
Overloading __iter__
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 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