I suppose you want to return several positions that match (domain == session.target_domain) then you must not use return (as it escapes the loop and exits the function scope). You should collect all your matches in a list and the return the list in the end. Something like:
def check(): result_list = [] for target_keyword in session.keywords.split(','): ... ... ... for idx, res in enumerate(results): ... ... if domain == session.target_domain: a_str = "Your google position is %d for keyword '%s' on domain %s" \ % (idx+1, target_keyword, session.target_domain) result_list.append(a_str) # Now you can return the list return result_list HTH On Wed, May 12, 2010 at 2:34 AM, Andrew Evans <evans.d.and...@gmail.com>wrote: > Hello I have a problem. I have code written for web2py that has two > functions, the problem is in the looping of the second function. it > only executes the loop once. Is there anyway I can continue looping > > def check(): > for target_keyword in session.keywords.split(','): > gs = GoogleSearch(target_keyword) > gs.results_per_page = int(session.results_per_page_num) > results = gs.get_results() > for idx, res in enumerate(results): > parsed = urlparse(res.url) > domain = mk_nice_domain(parsed.netloc) > if domain == session.target_domain: > return dict(search=build("Your google position is %d > for keyword '%s' on domain %s" % (idx+1, > target_keyword, session.target_domain))) > > Thanks if you can help > >