Hi;
I'm trying to tweak a script I found here:
http://zopelabs.com/cookbook/1118667115
to get it to do what I want. I'm no wizard at Python, much less newfangled
tools like yield. I understand that one cannot use "return" when working with
yield, but I don't understand how to achieve the same result. Here's my code:
from random import randrange
def getRandomQuote(top, topdown=True):
objs = top.objectValues()
num = 1
numAndQuote, quotes = [], []
for obj in objs:
if isdir(obj):
dirs.append(obj)
else:
quotes.append(obj)
if topdown:
yield top, dirs, quotes
for obj in dirs:
for x in getRandomQuote(obj, topdown):
yield x
if not topdown:
yield top, dirs, quotes
for q in quotes:
numAndQuote.append(num, q)
num += num
def isdir(obj):
if obj.meta_type == 'Folder':
return True
else:
return False
def demo(self):
root = self.restrictedTraverse('/theSite/en-us/Books')
num = randrange(1, len(num), 1)
luckyWinner = numAndQuote.pop(num)
path = '/'.join(luckyWinner.getPhysicalPath()) or '/'
return path
How can I stitch all this together to return the path? Or, how do I call the
demo after executing the yield?
TIA,
Javier
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index
--
http://mail.python.org/mailman/listinfo/python-list