Skip to content

Instantly share code, notes, and snippets.

@icshih
Created January 1, 2018 21:57
Show Gist options
  • Save icshih/ae7bd3fc92bdcb7714aa512aa308c34c to your computer and use it in GitHub Desktop.
Save icshih/ae7bd3fc92bdcb7714aa512aa308c34c to your computer and use it in GitHub Desktop.
Python Class cheat sheet
Display the source blob
Display the rendered blob
Raw
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