Solved

web service to iterate over la list returned

Posted on 2011-03-01
3
376 Views
Last Modified: 2012-05-11
I have built a web service using cherry.py and am having issues on what is most likley very simple.  I have a web service call that returns a list of strings and I simply need to print this back to the browser.

I have something like this:
for item in stat:
     return (item)

It will only return the first element and then stops. How to I iterate over all the list elements??
0
Comment
Question by:andrew_89
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35014076
Return returns.  So the first time through the loop you return.

Not sure exactly how you want to represent your list to your client but one way might be:

   return ",".join(stat)


Another way (which returns the same as the above just in a much more roundabout way):

   retval = ""
   for item in stat:
      retval += stat + ","

   return retval[:-1]


Another way (which returns your list JSONified):

   import json
   return json.dumps(stat)

0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 35014082
Sorry (typo):

   retval = ""
   for item in stat:
      retval += item + ","

   return retval[:-1]
0
 
LVL 1

Author Comment

by:andrew_89
ID: 35014152
awesome thanks, I am new to web services so this was throwing me..
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Downgrade Python 3.5 to 3.3 30 1,301
data scientists and AI 17 128
Python 3.5.2 - Script Help 3 94
Data frame to nested dictionary using to_dict 2 20
The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question