Skip to content

Instantly share code, notes, and snippets.

@amitkot
Created July 30, 2012 10:44
Show Gist options
  • Save amitkot/3206138 to your computer and use it in GitHub Desktop.
Save amitkot/3206138 to your computer and use it in GitHub Desktop.
Mock GetProcs for python course
#!/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