Created
July 30, 2012 10:44
-
-
Save amitkot/3206138 to your computer and use it in GitHub Desktop.
Mock GetProcs for python course
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
#!/usr/bin/python | |
class GetProcs: | |
d = [(i, i**2, i**3) for i in range(10)] | |
i = 0 | |
@classmethod | |
def GetFirstProc(cls): | |
print 'GetFirstProc - {} (i={}, d={})'.format(cls.d[cls.i], cls.i, cls.d) | |
cls.i = 0 | |
return cls.d[cls.i] | |
@classmethod | |
def GetNextProc(cls): | |
print 'GetNextProc - {} (i={}, d={})'.format(cls.d[cls.i], cls.i, cls.d) | |
cls.i += 1 | |
if cls.i >= len(cls.d): | |
return False | |
return cls.d[cls.i] | |
def iGetProcs(): | |
print 'iGetProcs' | |
nextProc = GetProcs.GetFirstProc() | |
yield nextProc | |
while nextProc: | |
nextProc = GetProcs.GetNextProc() | |
if nextProc: | |
yield nextProc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment