Created
January 1, 2018 21:57
-
-
Save icshih/ae7bd3fc92bdcb7714aa512aa308c34c to your computer and use it in GitHub Desktop.
Python Class cheat sheet
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
class members are public. | |
There is no way to reforce "private" members in the class | |
# simple class with generator | |
class ReadLogFile: | |
'''This class reads a log file input stream''' | |
def __init__(self, log_file): | |
self.log_file = log_file | |
def __iter__(self): | |
return iter(self.log_file) | |
i = T.__iter__() | |
conti = True | |
while conti: | |
try: | |
print(next(i)) | |
except: | |
conti = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment