Generators and co-routines

Terry Reedy tjreedy at udel.edu
Fri Mar 7 01:10:35 EST 2003


The .poll() method checks if the user is logged in, if not, calls the
.login() method (which is the co-routine/generator). My problem is the
.login() method is not being called! I put a print statement at the
start of the function, and nothing gets printed. I am entirely
unfamilar
with python generators, if someone can enlighten me, please do so!

------<CODE>------

class User:
def __init__(self, conn):
self.conn = conn
self.isLoggedIn = False

def poll(self):
if not self.isLoggedIn:
self.login()

def login(self):
print "in .login()"
....
-------------
perhaps what you want is
self.iter = self.login # in __init__
s = self.iter.next() # in poll
Note that login returns something that you might want to look at

Terry J. Reedy






More information about the Python-list mailing list