[Tutor] Generator function question?
Blake Winton
bwinton at latte.ca
Mon May 9 21:01:49 CEST 2005
Sorry for jumping in to this a little late, but...
> This is (IMO) more elegant:
> def neverEndingStatus():
> index = 0
> statusChars = ['|', '\\', '-', '/']
> while True:
> yield statusChars[index]
> index = (index + 1) % 4
Why not go a step further?
def neverEndingStatus():
statusChars = ['|', '\\', '-', '/']
while True:
for char in statusChars:
yield char
or
def neverEndingStatus():
while True:
yield '|'
yield '\\'
yield '-'
yield '/'
Later,
Blake.
More information about the Tutor
mailing list